FrontendDeveloper.in

JavaScript question detail

What is Hoisting

Hoisting is JavaScript's default behavior where variable and function declarations are moved to the top of their scope before code execution. This means you can access certain variables and functions even before they are defined in the code.

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.

Back to all JavaScript questions
Get LinkedIn Premium at Rs 399