Hoisting
Hoisting is a JavaScript behavior where variables and function declarations can be accessed before they are declared in the code because declarations are processed before execution.
Get Ayush’s stories in your inbox
Join Medium for free to get updates from this writer.
Example of variable hoisting:
console.log(message); // Output: undefined
var message = "The variable has been hoisted";var message;
console.log(message); // undefined
message = "The variable has been hoisted";Example of function hoisting:
message("Good morning"); // Output: Good morning
function message(name) {
console.log(name);
};Because of hoisting, functions can be used before they are declared.


