Step 4 of 10 · D · Updating the value
Replacing what's inside, in code
Remember the swap? Old value out, new value in.
Step 1 / 19recall
let score = 100;
score = 250;
console.log(score);Output
250
We saw the swap — old value out, new value in. Same name, same box.
In code, the line that replaces a value is shorter than the line that makes a new box.
Why? Because the box already exists. We are not making a new one — we are just changing what is inside.
In
js, ts, and dart, that means dropping the keyword: score = 250; — no let, no int.In
py, the line for update looks identical to the line for make — score = 250. The language figures out which one you mean from context.In
php, the box-name still wears its $: $score = 250;.Notice how similar the update line looks across all five — much closer than the declare lines were. That is worth noticing.
A common beginner mistake: writing
let score = 250 to update — but let means make a new box, not update.In some languages, that mistake is an error. In others, it silently makes a second box with the same name and hides the first one.
Rule of thumb: keyword on the first line, no keyword on the lines after.
Reading-order matters too: each line runs top to bottom, so the box holds whichever value was put in most recently.
Check yourself
Quick check
A box called `score` was already made with the value 100. Which JavaScript line correctly **updates** its value to 250?
Predict the output
js
let score = 100;
score = 250;
console.log(score);What does this print?
