All Articles
1 min read
Tutorial & GuidePublished on December 27, 2025

Understanding JavaScript Hoisting Clearly

Learn how hoisting works in JavaScript for variables and functions with clear examples.

TC
Think And Code TeamEngineering Insights

Introduction

Hoisting is a JavaScript behavior that often confuses beginners.

In this guide, we’ll explain what hoisting is and how it really works behind the scenes.

What Is Hoisting?

Hoisting is JavaScript’s behavior of moving declarations to the top of their scope.

Function Hoisting


sayHello();

function sayHello() {
  console.log("Hello");
}

Function declarations are fully hoisted.

Variable Hoisting


console.log(x);
var x = 10;

Variables declared with var are hoisted but initialized as undefined.

let and const

let and const are hoisted but remain in the temporal dead zone.

Final Thoughts

Understanding hoisting helps avoid unexpected bugs in JavaScript code.

TC

Written by Think And Code Editorial

We craft practical web development tutorials, mental models, and interactive quizzes to help developers build production-ready applications with clarity.

Put Your Knowledge to the Test

Try our instant AI-graded quizzes to test your understanding of JavaScript, React, and frontend development.