Data Types
Prerequisites: Variables
JavaScript's core types: number (both whole and decimal — there's no
separate integer type), string (text), boolean (true/false),
null (deliberately empty), undefined (not yet assigned), plus
object and array for structured data.
typeof 25 // "number"
typeof "25" // "string"
typeof true // "boolean"
typeof undefined // "undefined"
"25" (a string) and 25 (a number) look similar but behave
differently — "25" + "5" joins the text into "255", while 25 + 5
adds the numbers into 30.
Common mistakes
- Assuming text that looks numeric behaves like a number. Convert
explicitly with
Number("25")first.