let, const, and var
JavaScript has three ways to declare a variable. let and const (added in ES2015) are block-scoped and are the modern default; var is function-scoped and considered legacy.
let count = 1;
count = 2; // reassignable
const name = "Rahim";
// name = "Karim"; // ❌ TypeError: Assignment to constant variable
var legacy = "old style"; // avoid in new code
Use const by default, and reach for let only when you know a variable needs to be reassigned — loop counters, accumulators, or values that change over time. const does not make objects immutable; it only prevents reassigning the variable itself, so you can still mutate an object's properties or push new items into an array declared with const. var should be avoided in new code because of its function-scoping and hoisting quirks, which cause bugs that are hard to trace, especially inside loops and conditionals.