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 - Whats the difference between a function declaration and function expression?

​So, just to make sure I understand the concept - function declarations can be called BEFORE the code in which it was created because it was initially stored in the VO in the Global Execution Context, which means that you have access to it whenever.

However, function expressions are stored in a variable, and variables are initially defined as 'Undefined' until they are called. This is why you have to call the function AFTER the code in which it was created

Is that correct?

1 Answer

Steven Parker
Steven Parker
243,318 Points

You got it. And you correctly named the term that describes the difference: hoisting. :+1:

As you pointed out, variables are also hoisted, but they do not get their contents until the assignment statement is performed during sequential execution.