Learning object 2 of 100
Data type inspector
Type any JavaScript expression and inspect the value it produces: its type, how the console shows it, whether it is truthy, and how it converts to a number and a string.
Loading…
What it shows
Every value has a type. typeof names it, but has two quirks: typeof null is "object" and arrays are "object" too, which is why the inspector also shows Array.isArray. Conversions with Number() and String() explain many surprising results of +.
Guided experiment
- Inspect
"25"and then25. Which rows differ? - Inspect
""(an empty string). What does Number() give? Why is that a trap for form validation? - Inspect
nulland[]and compare typeof with Array.isArray.
Predict
What is typeof null?
Related
Lessons: Lesson 1: What JavaScript is and where it runs, Lesson 2: Your first JavaScript program, Lesson 9: Booleans, null and undefined
Projects: Project 1: Interactive Tip Calculator
Source: web/assets/js/objects/object-002.js in the companion repository.