Declaring Variables with let and const
A variable is a name for a value. You create (declare) a variable with a keyword. JavaScript gives you two keywords for this: let and const.
let makes a variable that you can reassign. That means you can give it a new value later, using just its name:
let score = 10;
console.log(score);
score = 25;
console.log(score);
Output:
10
25
const makes a variable that you cannot reassign. If you try, the program stops with an error:
const YEAR = 2026;
YEAR = 2027;
Output:
/box/index.js:2
YEAR = 2027;
^
TypeError: Assignment to constant variable.
at Object.<anonymous> (/box/index.js:2:6)
The first line of the error shows the file and the line number (line 2). Then you see the line itself, with a ^ under the place where the problem is. The TypeError line explains what went wrong.
So which one should you use? Use const by default, and use let only when the value really changes. In real programs, most values are set once and then only read. When you write const, readers know at once that the value stays the same. And if you change it by mistake, you get an error instead of a hidden bug.
JavaScript names use camelCase: the first word starts with a lowercase letter, and each next word starts with a capital letter, as in maxRetries or firstName. Almost all JavaScript code follows this style.
You may also see a third keyword, var, in old tutorials and old code. It was the only way to declare variables before 2015, and it has confusing rules that let and const fix. You can read it, but do not write it.
In the exercise, declare a score that changes with let and a city that never changes with const.