JavaScript · Junior · Question 17 of 75

Can you call a function before its declaration?

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

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).

Further reading

Problem with a question

JavaScript · Junior · question 17

Test yourself

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

Take this quiz