liveBook · Manning

Undefined

As explained in JavaScript in Depth

A special JavaScript value representing the absence of an assigned value or a missing result.

JavaScript uses undefined for a value that has not been assigned, was omitted, does not exist, or was never returned. That differs from null, which signals deliberate emptiness. The distinction exposes whether nobody supplied an answer or the program explicitly found no value. section 4.1 section 6.1.2

Use undefined for states that remain unset or unanswered:

  • Uninitialized variables, omitted function arguments, nonexistent properties, and functions without a return value. section 4.1
  • Check explicitly with === undefined when the distinction from null matters. section 4.1
  • Use val == null when either undefined or null should count as no value. section 4.1
  • Treat undefined as falsy, alongside null, false, numeric zero, NaN, and the empty string. section 4.6

Separate unset from intentionally empty

const record = { note: null, status: undefined }; record.note === null; // true: deliberately empty record.status === undefined; // true: not yet assigned function processValue(value) { if (value === undefined) return 'not set'; if (value == null) return 'no value'; return `processing ${value}`; } section 4.1

function processValue(val) {
  if (val === undefined) {  #A
    return 'not set';  #A
  }  #A
 
  if (val == null) {  #B
    return 'no value';  #B
  }  #B
 
  return `processing ${val}`;  #C
}

Trace a practical classifier that handles undefined first, then groups null with other absent values through deliberate loose equality. section 4.1

How JavaScript in Depth covers it

How deep it goes
Explains semantic conventions, falsiness, equality checks, and one runtime-specific representation, but does not develop coercion internals.
Examples
Uses object properties, value classification, omitted results, and constructor calls to expose undefined behavior.
What it assumes
Assumes basic JavaScript values, conditionals, functions, object properties, and equality operators.
What you can do after
Diagnose/debug with it by distinguishing unset data from intentional emptiness and choosing appropriate equality checks.
How it connects
Connects undefined with null, falsy values, loose equality, strict equality, function returns, and new.target.

Also explained in

Compare how 2 books explain undefined →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of JavaScript in Depth. The section links point to the parts of the book it draws on.