LESSON 05 / 07

Numbers, Strings & Booleans

Every value has a type. Meet numbers, strings, booleans, null and undefined — and learn why "5" + 5 is "55".

🎓Beginnerlevel
⏱️30 minto finish
✏️3activities

📂 First Steps in JavaScript🏷️ Variables

🎯 By the end of this lesson you can…

  • Identify the main types with typeof
  • Predict what + does with numbers and strings
  • Convert between strings and numbers

The main types

TypeExamplesThink of it as
number42, 3.14, -7amounts you can calculate with
string"hi", '42'text, always in quotes
booleantrue, falseyes / no answers
undefinedundefinedan empty box — never given a value
nullnulla box you deliberately emptied
⚡ JavaScript typeof.js 👆 Tap a line to explain it
1console.log(typeof 42);2console.log(typeof "42");3console.log(typeof true);4let mystery;5console.log(typeof mystery);

The + surprise

⚡ JavaScript plus.js 👆 Tap a line to explain it
1console.log(5 + 5);2console.log("5" + 5);3console.log("5" * 2);4console.log(Number("5") + 5);5console.log(String(99) + "!");

Booleans

⚡ JavaScript booleans.js 👆 Tap a line to explain it
1const isRaining = false;2const hasUmbrella = true;3console.log(10 > 3);4console.log(isRaining);
🔮 What will this display?
What does this print?
1console.log("3" + 4 + 5);
🔮 What will this display?
And this?
1console.log(3 + 4 + "5");
🛠️ Fix the total

price arrived as a string. Convert it so the program prints the correct total 450 for 3 items.

📌 Key takeaways

  • typeof x tells you a value’s type.
  • + adds numbers but joins strings — and a string wins.
  • Convert with Number("5") and String(5).

Finished reading & practising?

Saved in this browser. Create a free account to keep it forever.