Are function expressions hoisted in JavaScript?
No, not as functions. A function expression assigned to a var variable is hoisted as undefined. A function expression assigned to let or const sits in the TDZ. Either way, calling it before the line throws an error.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Function Hoisting vs Variable Hoisting in JavaScript
Function declarations are hoisted with their full body, so they can be called before the declaration line. var variables are hoisted with undefined, so referencing them early returns undefined and calling them as functions throws a TypeError.
The function declaration wins because it is hoisted with its full body while var is hoisted with undefined. If there are multiple function declarations with the same name, the last one wins.
Because the var variable is hoisted and initialized to undefined. The variable exists (no ReferenceError) but it is undefined, and calling undefined() throws TypeError: x is not a function.
Still have questions?
Browse all our FAQs or reach out to our support team
