Variables, Data Types, and Type Coercion
What this domain covers
Variables, the primitive types, and the coercion rules that decide what happens when types meet. Most exam items here are typeof checks, falsy/truthy judgements, and == versus === outcomes.
Declarations
var is function-scoped and hoisted with the value undefined. let and const are block-scoped and hoisted but uninitialised, so touching them before the declaration throws ReferenceError (the temporal dead zone). const needs an initialiser and blocks reassignment, not mutation: const o = {}; o.x = 1 is legal.
The type set
Seven primitives: string, number, boolean, undefined, null, symbol, bigint - plus object. typeof returns "undefined", "boolean", "number", "bigint", "string", "symbol", "function" for callables, and "object" for objects, arrays and null.
Falsy values
The complete falsy list is false, 0, -0, 0n, "", null, undefined, NaN. Everything else is truthy - including "0", "false", [], {} and " ".
Worked example
console.log('5' - 2, '5' + 2, [] + {}, null + 1)
Reasoning: - has no string overload, so '5' is converted with ToNumber → 3. + with a string operand concatenates → '52'. [] + {} runs ToPrimitive first: [] → '', {} → '[object Object]', giving '[object Object]'. null + 1 uses ToNumber(null) = 0 → 1. Note Number(undefined) is NaN, not 0.
Traps
typeof null === 'object'; test for null withx === null.NaN !== NaN; test withNumber.isNaN.0.1 + 0.2 !== 0.3because of binary floating point.Number('') === 0andNumber(' ') === 0.Boolean('false') === true, because any non-empty string is truthy.new Number(5)is an object, not a primitive.