javascript
Hoisting in JavascriptjavascriptLevel1
Progress0%
Contents
Hoisting in Javascript
1 / 13
Introduction
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.