Skip to the workspace
Pebellslearn by building
Data Types  ›  Lesson

Strings, Numbers and Booleans

Data Types 12 min

javascript / Strings, Numbers and Booleans

Explore each scene at your own pace.

01 · Strings, Numbers and Booleans

Strings, Numbers and Booleans

Strings, Numbers and Booleans

Strings represent text, numbers represent numeric values, and booleans represent true or false. A value’s type determines which operations make sense.

An article title is text, its reading time is a number, and its saved flag is a boolean.

See the mechanism

Walk through the modelStrings, Numbers and BooleansAuthored snapshots of the example; use Run below to test the code.
title"Quiet mornings"
minutes4
savedfalse
The three values describe different properties of one article.
1 of 3

Follow one example

javascript

The quotes make the title a string. The unquoted 4 is a number, so adding 1 gives 5. false is a boolean value, not the text "false". Each console.log prints one value; the variable names do not appear in the output.

Predict, change and check

Predict: What changes if minutes is "4" instead of 4? Predict the result of minutes + 1 before running it.

Test your explanation: Change only minutes to "4". You should see 41: + joins text when a string is involved. Restore 4 and confirm 5 returns.

The tasks below ask you to explain that result and apply the idea to different inputs.

Apply and distinguish

A type tells you which question you are answering

Keep a title as a string, a computed reading time as a number, and a saved flag as a boolean. The string 'false' is nonempty and therefore truthy; it is not the boolean false. A DOM input's text value is a string even when its visible characters look numeric.

An operator can expose a mistaken assumption: '4' + 1 joins text, while 4 + 1 performs numeric addition. Write down the expected input type before fixing the expression. Do not convert every value to a boolean to 'clean' a record; zero and empty text can be valid values whose information would be lost.

Check your understanding: State the input contract, identify the operation that changes the result, and give one boundary input that would distinguish the correct rule from the mistake described above.

Scene 1 of 2
Project context and further resources
Additional resources
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.