typeof on every primitive
Whole numbers and decimals share one type, number. And null reports object: that's the famous bug.
JavaScript has seven primitive types (string, number, boolean, null, undefined, bigint and symbol) plus objects; typeof tells you a value's type, with a few famous quirks.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Log the type of each of these values: "", 0, false, [], {}, null.
Write two lines that prove strings are copied by value: copy a string into a second variable, change the second one, and log both.
Explain it without notes
Name JavaScript's primitive types. What makes a value primitive?
Why is typeof null equal to "object", and how do you correctly check for null and for arrays?
What is the difference between null and undefined?
How can "abc".length work if strings are not objects?
Console
(nothing was printed)Expected console output
string
number
number
boolean
undefined
object
bigint
symbol