Home›Community›What is the difference between var, let, and const in JavaS…
What is the difference between var, let, and const in JavaScript?
Coding Now Expert •
Jun 13, 2026 •
256 views
All three declare variables, but with different scope and mutability:
**var:** function-scoped, hoisted, can be redeclared
**let:** block-scoped, not hoisted, cannot be redeclared
**const:** block-scoped, cannot be reassigned
```javascript
if (true) {
var x = 1; // accessible outside the if block
let y = 2; // only inside the if block
const z = 3; // only inside, cannot change
}
console.log(x); // 1
console.log(y); // ReferenceError
```
Best practice: Use **const** by default, **let** when reassignment needed, avoid **var**.