Variable Declaration in JavaScript
From the JavaScript cheat sheet · Variables & Data Types · verified Jul 2026
Variable Declaration
Different ways to declare variables
javascript
// const - block-scoped, cannot be reassigned
const name = 'John';
// let - block-scoped, can be reassigned
let age = 30;
age = 31; // OK
// var - function-scoped (avoid in modern JS)
var oldStyle = 'legacy';💡 Always prefer const by default, use let when reassignment is needed
⚡ const prevents reassignment but not mutation of objects/arrays
📌 Block scope means variables exist only within { }
🚫 Avoid var due to hoisting and function scope issues