var, let, and const
var is function-scoped, while let and const are block-scoped. const prevents reassignment of the binding, but it does not make referenced objects immutable. This distinction between binding immutability and object immutability is essential.
Modern JavaScript generally favors const by default and let when reassignment is actually required.
Binding vs Object Mutation
const user = { name: 'Suriya' };
user.name = 'Alex';
console.log(user.name);
// user = {}; // TypeError💡 The const binding cannot point to another object, but the object itself remains mutable unless you explicitly enforce immutability.
Key Takeaways
varis function-scoped.letandconstare block-scoped.constprotects a binding, not the contents of an object.
Knowledge Check
What does `const` guarantee?