Function Declaration vs Expression
Question
What is a key difference between a function declaration and a function expression?
Hint
Think about when you can call the function relative to where it appears in the code.
Explanation
Function declarations (e.g., function foo() {}) are fully hoisted — you can call them before they appear in the code. Function expressions (e.g., const foo = function() {}) are not hoisted as functions — the variable is hoisted but not the function value, so calling before the line throws an error.
Related Resources
Related Lessons
- JavaScript Functions
Learn about function declarations and expressions.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.