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

Hoisting

I'm not native English speaker, and sorry for my English. When we declare function expression, we can't call function before it's made. I like this arrow syntax, but what is better to use arrow/expression function or function declaration? I think that arrow teaches us to better organize our code.

1 Answer

Christopher Debove
PLUS
Christopher Debove
Courses Plus Student 18,373 Points

Arrow functions is juste some normal function expression for which the context is the current context. Then between function expression and function declaration... I think it's more a question of preference.

Declarations are parsed before every code in the scope so even if you declare the function at the bottom (even after a return), the function will exists

Expression are cooler (in my humble opinion) because it's just a reference to an anonymous method. It can be garbage collected, you can change the reference.