What is JavaScript Hoisting

In JavaScript, variable and function names can be used before declaring it. The JavaScript compiler moves all the declarations of variables and functions at the top so that there will not be any error. This is called hoisting.

Hoisting is only possible with declaration but not the initialization. So the initialization still happen where it is written

console.log(value);
var value = 1;
Output
undefined

Only work with var keyword

console.log(value);
let value = 1; // Error ReferenceError: Cannot access 'value' before initialization