Todas las publicaciones
post5 de mayo de 2026

var vs let vs const

#javascript#scope#hoisting#variables#interview
var vs let vs const — slide 1var vs let vs const — slide 2
What are the exact differences between var, let, and const in JavaScript?

**var**: function-scoped (or global), hoisted and initialized to undefined, can be re-declared, can be reassigned. **let**: block-scoped, hoisted but NOT initialized (temporal dead zone), cannot be re-declared in same scope, can be reassigned. **const**: block-scoped, hoisted but NOT initialized (TDZ), cannot be re-declared, cannot be reassigned (but the referenced object IS mutable). ```js if (true) { var a = 1; // leaks out let b = 2; // block-scoped const c = 3; // block-scoped } console.log(a); // 1 console.log(b); // ReferenceError console.log(c); // ReferenceError ``` Rule of thumb: always const, use let when reassignment is needed, avoid var.