Navigating Variable Declarations in JavaScript: A Tale of let, var, and const
In the bustling city of JavaScript, where lines of code construct the digital world we interact with, variables stand as the foundational building blocks, holding, and managing data throughout our applications. Today, let’s embark on a journey through the streets of JavaScript, exploring the distinct neighborhoods of let
, var
, and const
, understanding their unique characteristics, and discerning when and how to visit (use) each one.

🚗 var
: The Classic, Hoisting Vehicle of JavaScript
In the early days of JavaScript city, var
was the only means to declare variables. But var
comes with its quirks, notably hoisting, where variables are lifted to the top of their functional or global scope, regardless of where they are declared.
Example:
console.log(x); // undefined, not ReferenceError!
var x = 5;
Imagine declaring to pay at a shop (variable declaration) and being allowed to take the goods (use the variable) even before you actually declare to pay. That’s var
for you - a bit lenient and potentially confusing for the uninitiated traveler.
Keep reading with a 7-day free trial
Subscribe to Bragadeesh’s Substack to keep reading this post and get 7 days of free access to the full post archives.