JavaScript types, equality, and coercion

JavaScript has seven primitive types (number, string, boolean, undefined, null, symbol, and bigint) and objects. typeof reports the type of a value, with one famous quirk: typeof null is "object". All numbers are 64-bit floating-point values, which is why 0.1 + 0.2 is not exactly 0.3.

JavaScript
console.log(typeof 42, typeof "text", typeof true, typeof undefined, typeof null, typeof {}, typeof []);
console.log(0.1 + 0.2 === 0.3, Math.abs(0.1 + 0.2 - 0.3) < Number.EPSILON);
console.log("5" + 3, "5" - 3, "5" * "2");
console.log(1 == "1", 1 === "1", null == undefined, null === undefined);
console.log(Boolean(""), Boolean("0"), Boolean(0), Boolean([]), Boolean(NaN));
console.log(NaN === NaN, Number.isNaN(NaN));
Read the full lesson