🔥 Declaring vs Defining vs Initializing Variables in JavaScript

If you've ever heard people talking about "declaring," "defining," or "initializing" variables in JavaScript and felt confused — you’re not alone! These words sound similar, but they mean different things.
🟢 Declaration
When you declare a variable, you're telling JavaScript to create a placeholder for it in memory. However, at this point, it doesn’t yet hold a value.
let a;
var b;
- Here,
a
andb
are declared but not given any values yet.
🟡 Initialization
When you initialize a variable, you assign it a value for the first time.
let a;
a = 10; // Initialization
You can also declare and initialize at the same time:
let x = 5; // Declaration + initialization
For const
, you must initialize immediately:
const y = 20; // Declaration + initialization required
🔵 Definition
In JavaScript, the term definition is sometimes used informally to describe the combination of declaration and initialization together:
let name = "JavaScript"; // Declared and initialized (defined)
For functions, "definition" means providing both the name and its body (implementation):
function greet() {
console.log("Hello!");
}
⚖️ Quick Recap Table
Term | Meaning | Example |
Declaration | Reserve a name in memory | let a; |
Initialization | Assign first value | a = 10; |
Definition | Declare and assign together | let b = 5; |
💬 Conclusion
Declare first, initialize later — possible with
var
andlet
.Must initialize immediately with
const
.
Subscribe to my newsletter
Read articles from pushpesh kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
