Declaring Variables with let and const

When to use let, when to use const, and why var is best left behind.

Modern JavaScript gives you two ways to declare a variable: let and const. Reach for const by default, and only use let when you genuinely need to reassign.

const name = 'Ada';
let score = 0;
score = 10; // fine — declared with let

Both are block-scoped, so they only exist inside the { } they’re declared in — far more predictable than the old var.