freecoding.school100% FREE · NO SIGNUP
Script SpringsISSUE #7 of 29

data types · primitives vs objects

SparkyVSNaN the Trickster
Sparky saysJS has primitives (string, number, boolean, null, undefined, bigint, symbol) and objects (everything else).

Seven primitive types hold single values and are copied by value. Everything else — arrays, functions, dates, plain objects — is an object, copied and compared by reference. typeof reveals a value's type (with the famous quirk that typeof null is "object").

Power-ups you unlock

NaN the Trickster attacks — common mistakes

Boss battleLog typeof for a string, number, array, function, and null — note the surprises.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>const t=[typeof 'a',typeof 1,typeof [],typeof (()=>{}),typeof null];
document.getElementById('o').textContent = t.join('\n');</script></body></html>
▶ Open the interactive comic issue
‹ Hoisting · What Runs Before WhatNumbers · Int · Float · NaN · Infinity ›