JavaScript · Middle · Question 60 of 75

What happens when this code runs?

greet();
var greet = function () { console.log("hi"); };

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.

Further reading

Problem with a question

JavaScript · Middle · question 60

Test yourself

Take the JavaScript · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz