CODERNEXv1.0.0-stable
$whoami$ls_projects$cat_blog$ssh_contact
sudo login
CPU: 2.4%
PING: 24ms
Terminal_Navigation_Menu
>Aboutwhoami>Projectsls_projects>Blogcat_blog>Contactssh_contact
INITIALIZE_LOGIN

Engineer: Borhan Uddin [cite: 1]

Base_Loc: Khulna, Bangladesh [cite: 2]

Status: SESSION_ACTIVE
cd ../blog

JavaScript Hoisting Explained: The Complete Guide

Borhan Uddin
2026.01.11
5 MIN_READ
3 HITS
JavaScript Hoisting Explained: The Complete Guide

What is hoisting in JavaScript?

Javascript Hoisting is javascript's default variable which moves all the declarations at the top of the script.

Like, A variable can be used before it has been declared.

Example:

javascript
/** 
* For hoisting the variable x is now on the top of the script;
* var x;
**/

x=5; // Initializing the variable x

console.log(x) // 5

var x; // Declaring the variable x

Varibale Declared with let and const:

variable declared with let and const are also hoisted to the top of the script but it will not be initialized;

Meaning: The block of code is aware of the variable, but it cannot be used until it has been declared.

variable with let keyword:

Using a variable with a let keyword before it is declared will result in a ReferenceError.

javascript
firstName='Codernex';

console.log(firstName); // ReferenceError

let firstName;

variable with the const keyword

Using a const variable before it is declared, is a syntax error, so the code will simply not run.

javascript
// This code will not run.
carName = "Volvo";
const carName;

Remember Javascript hoisting only works with the declaration, not with the initialization;

javascript
/**
* Javascript hoisting only move the variable declaration to the 
* top of the script, not the initialization that's why it will 
* print undefined
* It will look like - var x; but it will not be initialized with the value 5;
*/
console.log(x) // undefined
var x=5; // Declaring & Initializing with 5;

Declare Your Variables At the Top!

Hoisting is (to many developers) an unknown or overlooked behavior of JavaScript.

If a developer doesn't understand hoisting, programs may contain bugs (errors).

System_Menu
ls ./projectsssh ./contact

Identity_Verified

Author: Borhan Uddin

Role: Sys_Admin

End of Buffer — All Systems Operational