OpenViSTAI · Agents · Blockchain · Crypto
Menu

OPENVIST LEARN · FREE LESSONS

Types, missing values and strict equality

Recognise primitive values and avoid accidental coercion in comparisons.

Lesson 3 of 25 · About 20 minutes · Beginner · English

By the end of this lesson

Use typeof and === while treating null and arrays explicitly.

Before you start

  • Node.js 24 with a terminal and plain-text editor; the browser-only lesson is labelled separately.
  • Complete lesson 2 or be comfortable with its examples.

Three words to know

Primitive
A basic value such as a string, number or boolean.
Coercion
An automatic conversion between types.
Strict equality
=== compares without converting different primitive types to match.

1. Text digits remain text

Quotation marks make a string. A string containing digits is not automatically a number for every operation: + may concatenate text. Use explicit conversion at a known input boundary and strict equality in conditions.

Compare values deliberatelyJAVASCRIPT · Node.js · save as lesson.mjs
const raw = "4";
console.log(typeof raw);
console.log(raw === 4);
console.log(Number(raw) === 4);
console.log(raw + 1);
What you should see · example output
string
false
true
41

2. Missing is not the same as empty

undefined often means that a property or return value was absent. null is an explicit value frequently used to mean no result. Neither is an empty string or zero. There is a historical typeof quirk: typeof null returns object, so use value === null when testing for null.

Inspect missing valuesJAVASCRIPT · Node.js · save as lesson.mjs
const record = {};
console.log(record.name === undefined);
console.log(null === undefined);
console.log(typeof null);
console.log(Array.isArray([]));
What you should see · example output
true
false
object
true

3. Type checks are only one rule

JavaScript also has bigint and symbol primitives. This route mainly uses strings, numbers, booleans, null and undefined plus objects and arrays. typeof value === "number" does not prove a finite integer: NaN and Infinity are also numbers. The next lesson adds numeric checks.

YOUR TURN

A small check before you continue

Predict "0" === 0, null === null and Array.isArray({}).

Show a suggested answer

They are false, true and false. An ordinary object is not an array even though both have typeof object.

Sources and scope

Documentation and examples reviewed 2026-10-18. Provider screens, package versions and output wording can differ. Examples show expected outcomes; they are not a claim that OpenViST connected to your server or verified your setup.