JavaScript · Junior · Question 6 of 75

What does this code print?

console.log(x);
var x = 5;

Explanation

The var declaration is hoisted to the top of the function and initialized with undefined, while the assignment stays in place. With let or const this would be a ReferenceError.

Further reading

Problem with a question

JavaScript · Junior · question 6

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