javascript
javascript
Hoisting in Javascript
Live
bolt
Level1
Progress0%

Hoisting in Javascript

CARD 1

Introduction

Login to report note issues for this section.

Hoisting

Hoisting is JavaScript's default behaviour of moving declarations to the top of their scope before any code is executed. It is not a physical movement of code — JavaScript's engine processes declarations first during a compilation phase before running the code line by line.

The result is that certain variables and functions can be referenced before the line where they are written.

codejs
1console.log(name); // undefined — no error, even though name is declared below
2var name = "Arjun";

Understanding hoisting explains many confusing JavaScript behaviours and is essential for understanding why let, const, and function expressions behave differently from var and function declarations.