Lazy Ant Lab
var vs let vs const: Not Syntax, It’s About Behavior

var vs let vs const: Not Syntax, It’s About Behavior

engineering
Mar 26, 2026

The difference between var, let, and const is often explained as simple syntax rules. But the real difference is about behavior and predictability. This article breaks it down in a simple, practical way.

A classic JavaScript interview question:

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

Typical answers:

  • var is old

  • let/const are new

  • const cannot change

But that’s not the real answer.

The real question is:
🐜 Do you understand how your code behaves?

Think simple

When you declare a variable, you're deciding:

  • where can I use this?

  • how can it change?

That’s where var, let, and const differ.

Scope (this is the real deal)

typescript
  • var → “I’m everywhere”

  • let/const → “I stay here”

🐜 one is uncontrolled
🐜 the other is predictable

Hoisting (properly understood)

typescript
typescript
  • var → exists but empty

  • let/const → not accessible yet

TDZ

typescript

It simply says:

🐜 don’t use it before defining it

This prevents bugs.

const is misunderstood

typescript

const does NOT freeze values.
It freezes the reference.

Why var is dangerous

typescript

That’s not flexibility.
That’s risk.

Real-world bug

typescript
typescript

If you don’t understand this:

🐜 you will ship bugs

What to use?

  • default → const

  • changing → let

  • avoid → var

Lazy Ant perspective

This is not about keywords.

It’s about:

🐜 how predictable your code is

Good systems:

  • don’t surprise you

  • have clear boundaries

  • behave consistently

Conclusion

This looks like a small detail.

But:

  • scope bugs

  • async issues

  • unexpected behavior

often start here.

It’s not about syntax.
It’s about control.

And good engineering is about building systems you can control.

Connect with the author:

Continue Reading —