JS BASICSChapter 1 · JS Basics
Types and Conversion
typeof tells you what kind of value you have: "number", "string", "boolean", "object" or "undefined". Convert on purpose with Number("42"), String(42) and Boolean(value). JavaScript also converts automatically in some places, which surprises people: "5" * 2 is 10, but "5" + 2 is "52". The values 0, "", null, undefined and NaN are falsy; everything else is truthy.
Worked example
How it reads
Number("sky")cannot convert, so it gives NaN (not a number)*always does maths, but+joins text if either side is a string- Empty text and 0 are falsy, so
Boolean("")is false

Cloud tip: Convert input explicitly with
Number(...) as soon as you receive it, instead of relying on automatic conversion later.

