🎯 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
| Type | Examples | Think of it as |
|---|---|---|
| number | 42, 3.14, -7 | amounts you can calculate with |
| string | "hi", '42' | text, always in quotes |
| boolean | true, false | yes / no answers |
| undefined | undefined | an empty box — never given a value |
| null | null | a 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 xtells you a value’s type.+adds numbers but joins strings — and a string wins.- Convert with
Number("5")andString(5).
Finished reading & practising?
Saved in this browser. Create a free account to keep it forever.