Three keywords declare variables, but only two belong in modern code.
Direct answer
Use const by default, let when you need to reassign, and avoid var. let and const are block-scoped and safer. var is function-scoped and hoisted in confusing ways.
Comparison
var | let | const | |
|---|---|---|---|
| Scope | function | block | block |
| Reassign | yes | yes | no |
| Redeclare | yes | no | no |
| Hoisting | yes, value is undefined | yes, but unusable before declaration | same as let |
Examples
const name = "Ada";
let count = 0;
count = count + 1;
if (true) {
let inside = "block only";
}
// inside is not available here
const does not mean frozen
const list = [1, 2];
list.push(3); // allowed
list = []; // error
A simple rule
- Start with
const. - Switch to
letif you need to reassign. - Do not use
var.
Where Teyro fits
Teyro's JavaScript for Beginners course turns this into short lessons you can play in a few minutes a day. It has 50 lessons, and you can start free.
The bottom line
Prefer const, use let when needed and leave var to older code.



