Skip to content
Your progress

Checking your sign-in…

Who's learning?

Each profile keeps its own read lessons, badges, streak, and practice scores on this device.

Lesson 2 of 11

A box you can change, and a box you cannot

Show on a big screen

7 min

Text size

The bus has 32 seats, and that number does not change. The number of people in the queue outside the gate changes.

Loading lab…

Two boxes made: waiting = 18, seats = 32.
Step 1 of 4
  1. Two boxes made: waiting = 18, seats = 32.
  2. waiting can refill: waiting = 24.
  3. seats cannot refill. 40 is refused.
  4. seats still holds 32. The run stops here.

The rule

let can be given a new value later. const cannot. The machine stops the run if you try.

let waiting = 18;

const seats = 32;

In code, = means store, not equals. The box on the left receives the value on the right.

The two words that make a box, and what each promises
WrittenCan a later line replace it?
let waiting = 18;Yes
const seats = 32;No

const does not mean secret or important. It means the box cannot be refilled after it is made. So const suits the seats, and let suits the queue.

waiting = waiting + 6; looks odd. It is not a Maths equation. The right side is worked out first. With waiting at 18, that gives 18 + 6 = 24. Then 24 is stored in waiting.

Try to change a const and the run stops. The machine names the box and says why:

seats was made with const, so it cannot change. Use let if it should.

Try the lab to finish this lesson.