Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Introducing Functions

Alex Sorrells
Alex Sorrells
530 Points

Just curious..

So this is me just being curious, but the second method of creating a function in the anonymous.js file seems odd, I cant see how it would be any better than the way you taught in the random.js file

1 Answer

Steven Parker
Steven Parker
231,271 Points

You're right, in these examples there's not really any significant difference. At this point they just want you to be able to recognize both kinds and understand them when you see them in other code.

But in more complex code, function expressions can be useful for situations involving callbacks, hoisting or closures. If you continue with your JavaScript studies, these concepts will be introduced in later courses. Or you can find more information on this MDN documentation page.