Skip to content

L01 Values and assignments

12 minStart here

Outcome

Read literals, names, expressions, and assignments, then state a variable's value after a named line.

Learn

A value is a piece of data such as a number, string, or Boolean. A variable is a name the program uses to refer to a value. The right-hand expression is evaluated before the result is assigned.

In JavaScript, use let for a binding that is reassigned and const for a binding that will not be reassigned. Python doesn't need either keyword.

Worked example

Predict copy and total after line 4. Start with an empty table, then write each name and its new value.

JavaScript
let total = 4;
total = total + 3;
const copy = total;
total = total - 1;
Predict first, then show the worked explanation

After line 2, total is 7. Line 3 binds copy to the number 7; line 4 changes total to 6. The earlier copy stays 7.

After linetotalcopy
14
27
377
467

Practice and check

Guided practice

Practice, not scored

Change the starting number on line 1 to 8. What does copy hold after line 4?

Choose one answer

Exit check

Counts toward completion

After let n = 2; n = n * 4; const saved = n; n = 0;, what is saved?

Choose one answer

Common mistake

Reading an assignment as a permanent algebra equation. Ask: what is on the right now, and which name receives it?

Next

In the next lesson, follow a value through an if.

References