Hoisting - Easy To Explain

ShubhradeepShubhradeep
1 min read

Hoisting

Hoisting in JavaScript is a behavior where variable and function declarations are moved to the top of their scope during the compile phase, before the code is executed.

This means you can use functions and variables before their actual declaration in code - but only their declarations are hoisted, not their initial values. Variables are initialized with undefined and functions are initialized with whole function

Variables declared with 'let' and 'const' are also hoisted, but they are not initialized, so accessing them before declaration causes a ReferenceError (Temporal Dead Zone).

But for variable with var it's initialized with undefined so if not cause any reference error, it will show undefined

0
Subscribe to my newsletter

Read articles from Shubhradeep directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shubhradeep
Shubhradeep

Full-Stack Developer with 1.5 years of experience building scalable, secure web applications using React, Node.js, and PostgreSQL. Skilled in REST APIs, backend architecture, authentication (JWT/JWE), and modern frontend tools. Proven ability to enhance system efficiency, SEO, and user experience.