You might have heard of Flag hoisting , but what the fuck is hoisting in JavaScript ?
There are two types of hoisting, variable hoisting and function hoisting.
Variable hoisting :
By default JavaScript move all declarations to the beginning of the current scope or current function.
There are two types of hoisting, variable hoisting and function hoisting.
Variable hoisting :
By default JavaScript move all declarations to the beginning of the current scope or current function.
Example 1 : Variable hoisting in very outer scope
x = 5; // Assign/defining 5 to x
console.log(x)
var x; // Declare x
BUT this is How it will be Executedvar x; // Declare x
x = 5; // Assign/defining 5 to x
console.log(x)
Observation : See the difference var x; // Declare x is set to the beginning for scope