let & const (JavaScript)

let and const are the modern ways to declare variables in JavaScript. Use const for values that never change and let for values that do.

JavaScript

const and let are block-scoped (they only exist inside the { } where they're declared), unlike the older var. Reach for const by default and switch to let only when you need to reassign.

Examples

JavaScript

const PI = 3.14;
let count = 0;
count = count + 1;
console.log(PI, count);

Output:

3.14 1

See also

Back to the Dictionary