JSE Certified Entry-Level JavaScript Programmer study materials
JSE Certified Entry-Level JavaScript Programmer study resources

JSE Certified Entry-Level JavaScript Programmer: Variables, Data Types, and Type Coercion

JSE Certified Entry-Level JavaScript Programmer · Work through your exam, one topic at a time.

All guide sections

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 with x === null.
  • NaN !== NaN; test with Number.isNaN.
  • 0.1 + 0.2 !== 0.3 because of binary floating point.
  • Number('') === 0 and Number(' ') === 0.
  • Boolean('false') === true, because any non-empty string is truthy.
  • new Number(5) is an object, not a primitive.