JavaScript · Middle · Question 60 of 75
What happens when this code runs?
greet();
var greet = function () { console.log("hi"); };- ✓Correct answer:
TypeError: greet is not a function- only thevardeclaration is hoisted, asundefined - 2It prints
hi - 3
ReferenceError: greet is not defined
Explanation
Function declarations are hoisted with their body; function expressions follow the hoisting rules of the variable. With let or const you'd get a ReferenceError from the TDZ.