What’s the difference between var, let, and const?

25 Feb 2026 | Pradeep Kumar

Sound's simple on paper yet this question still trips experienced developers.

JavaScript gives us three ways to declare variables. They seem interchangeable until one of them ruins your evening and sends you debugging at 2 AM.

In this guide, we’ll clearly break down how var, let, and const work — and when to use each.

Jackie Chan Confusion on javascript variables

The Chaotic Era of var

Before ES6 (2015), JavaScript only had var which let to problems such as:

To fix these issues, ES6 introduced two variables named:

1.Var (Old School)

Before ES6, var was the default setting for every variable. It didn’t care about block boundaries, happily leaked into places it shouldn’t, and occasionally created bugs that made developers question their life choices.

How var Works:

var name = "Clark Kent"
var name = "Definitely not Superman"
console.log(name) // prints Definitely not Superman

Because var is function scoped, it ignores all bondaries like a boy bestie.

if(true){
    var message = "Message Works"
}
console.log(message) // prints "message works, not checking any boundaries"

2.Let (The well behaved guest)

let was introduced in ES6 to fix the scope problems caused by var. A variable declared with let is block scoped, meaning it only exists inside the { } where it is defined.

This makes your code more predictable and prevents variables from leaking into places they shouldn’t be.

You can change the value later, but you cannot declare it again in the same scope.

Think of let as a well-behaved variable, it stays in its lane and only shows up where it’s invited.

How let Works:

let deadline = "Next Week"
let deadline = "Tonight" // Fails to print since let is declared two times. 

But you can redeclare the values like this

let sleephours = 8
sleephours = 4 
console.log(sleephours) // Prints 4

Var only works inside the block. Outside the block it acts like it never existed

if(true){
    let work ="Done"
}
console.log(work); // Error not accessible outside its block.

Const (The School Principal)

const was introduced in ES6 to declare variables whose values should not be reassigned.

Like let, it is block scoped, meaning it only exists inside the { } where it is defined. Once a value is assigned to a const variable, it cannot be changed or redeclared.

This helps prevent accidental changes and makes your code safer and easier to understand.

Think of const as a promise: once set, it stays that way.

How const Works:

Once const variable is declared we cannot reassign the values

const pi = 3.14
pi = 365
console.log(pi)// Error cannot redeclare the values once const is used.

But objects can change it's value internally

const diet ={ start: "Monday" };
diet.start = "next Monday"; // Prints next Monday
console.log(diet);

As let it is also block scoped

if(true){
    let work ="Done"
}
console.log(work); // Error not accessible outside its block.

When you should use Each?

A Short Recap

Final Thoughts

JavaScript seems confusing… until you understand it and start questioning your life choices.

If you enjoyed this quick guide, you can read more developer-friendly tips on my blog. I regularly share insights on coding, productivity, and building better projects.

Let’s connect — follow me on Twitter and LinkedIn so you don’t miss future posts.