console.log(x);
var x=10;
//hoisting converts the above code to
var x;
console.log(x);
x=10;
When a script runs in JavaScript Engine, all the var
keyword declarations of variables move up to the top of program(hoisting variables), and the initializations and the statements follow the written order.
Time between initialization and declaration of a variable.
console.log(myVar); // ReferenceError: Cannot access 'myVar' before initialization
let myVar = 9;