A common interview question: Do you know about variable promotion? Or, what is the difference between var and let? One of the answers must be that var boosts variables while let does not.

Discussion:

console.log(a); var a = 1; // the output is undefinedCopy the code
console.log(b); let b = 1; Uncaught ReferenceError: b is not definedCopy the code

Var refers to the top of the current scope when declaring a variable, and the assignment is left at the same place.

var a;
console.log(a);
a = 1;
Copy the code