variables and functions can be accessed before their actual declaration, and the term used to describe this in JavaScript is âHoisting.â
term âhoistingâ is mostly associated with function declarations and variables declared with the
âvarâ keyword
Function declarations, just like variables declared using the âvarâ keyword, are also hoisted.
the functionâs name is registered as a variable in the scope containing the function declaration, and it is initialized with the function itself.
To be able to call a function before or after the function declaration is really useful and frees the developer from arranging the code in such a way that every function declaration comes before it is called.
helps in code organization
In ES2015, the ECMAScript specification defined standard and legacy rules for handling function declarations
the function declarations inside blocks are hoisted to the top of the block, converted into a function expression, and assigned to a variable declared with the let keyword.
The function hoisted inside the block is limited to the containing block and cannot be accessed by code outside the block containing the function.
It is important to note that the standard rules only come into effect in strict modeÂłâ°.
var count = 5;
{
console.log(count); // hoisted but cannot access due to TDZ
let count = 10;
}
var
variables, they are assigned the value of undefined
until their declaration is executed."uninitialized"
.