Skip to main content
InterviewHubPRO
Section Overview
Q29

Question 29 of 536

Part 1: Core Objects, Prototypes, Functions & Scope (1 - 53)

5%
JavaScript & V8 Internals (536 Qs)•Part 1: Core Objects, Prototypes, Functions & Scope (1 - 53)

What is Hoisting

junior LevelMost AskedCode ExampleClosures & ScopePrototypes

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:

js
console.log(message); // Output: undefined
var message = "The variable has been hoisted";
js
var message;
console.log(message); // undefined
message = "The variable has been hoisted";

Example of function hoisting:

js
message("Good morning"); // Output: Good morning

function message(name) {
console.log(name);
}

Because of hoisting, functions can be used before they are declared.