Hoisting in javascript
Hoisting is JavaScript's behavior of moving variable and function declarations to the top of their scope. var declarations are hoisted and initialized with undefined, while let/const are hoisted but stay in the temporal dead zone until declared.
Example
console.log(a); // undefined (var is hoisted)
var a = 10;
// console.log(b); // ReferenceError (temporal dead zone)
let b = 20;var is hoisted and initialized to undefined, so reading it before assignment does not crash; let/const are not usable before their declaration.