JavaScript · Junior · Question 17 of 75
Can you call a function before its declaration?
greet();
function greet() { console.log("hi"); }- ✓Correct answer: Yes: a function declaration is fully hoisted
- 2No: it throws a
ReferenceError, as withlet - 3No: it throws
TypeError: greet is not a function
Explanation
Function declarations are created before code in their scope runs. With a function expression (const greet = function () {}), calling before the declaration fails: the variable is in the TDZ (or undefined with var).