Do you know what will be the output of this code?
JavaScript
console.log(a);
var a = 5;
Show answer and explanation
The answer is undefined.
The declaration var a is hoisted to the top and initialized with undefined. The assignment a = 5 stays where it is, so it hasn’t run yet when console.log executes.