A box you can change, and a box you cannot
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.
waitingcan refill: waiting = 24.seatscannot refill. 40 is refused.seatsstill 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.
| Written | Can 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.