Variables with let
Boxes for values.
A variable is a named box that holds a value. You put a value in, and later use the name to get it back. You can even replace what's in the box. In modern JavaScript, we make changeable variables with let.

- A named box
- Put a value in, get it back
- let
Making and changing a variable
Let score equals zero creates a box called score, holding zero. Later, we put a new value in it, without writing let again. And score equals score plus ten takes the old value, adds ten, and stores the result. Run it.
let score = 0;
console.log("Start:", score);
score = 50;
console.log("Now:", score);
score = score + 10;
console.log("After bonus:", score);Start: 0 Now: 50 After bonus: 60
Shortcuts
Adding to a variable is so common that there's a shortcut. Score plus equals ten means score equals score plus ten. Minus equals, times equals, and divide equals work the same way. And plus plus adds exactly one, which is handy for counting.
| key | value |
|---|---|
| x += 10 | x = x + 10 |
| x -= 3 | x = x − 3 |
| x *= 2 | x = x × 2 |
| x++ | add one |
Summary
Let creates a variable whose value can change. Use equals to give it a new value. Next, const, for values that shouldn't change.
Key takeaways- let name = value
- name = new value
- += and ++