Lesson 4 of 5 · 8 minutes

Changing a variable's value

A variable made with let can receive a new value. This is reassignment.

score = score + 1; reads the current score, adds one, and puts the result back into the same box. The label stays. The value changes.

Use const when a value should not change. A const box cannot be reassigned. This protects values that should stay fixed.

A box labelled score changes its value from 0 to 1

Same label, new value.

Loading the editor…

Run it twice. Each run starts the whole program again, so it prints 1 both times.

Quick check

Which keyword allows a value to be reassigned?

Choose one answer.

Why does a fresh run print 1 again, not 2?

Choose one answer.

You can now change a variable's value — and lock one with const when it should stay fixed.