undefined, JavaScript's Extra Flavor

JavaScript has a second kind of nothing, and this one has no Python equivalent at all.

null means someone deliberately set this to nothing.

undefined means nobody ever set this at all.

A variable you declare but never assign is undefined. An object property that doesn't exist is undefined. A function that returns nothing gives back undefined.

EXAMPLE
loading editor…
YOUR TURN
Your turn → Fix the Python version: create never_set above the print and give it a value. Then, in JavaScript, give neverSet a value and add an age to person.
loading editor…

Syntax has to be exact. Every quote, bracket and parenthesis needs its partner, and in Python the spaces at the start of a line count. One slip and the program won't run; the message will say where.

✦ Direct equivalent, similar concept, or language-specific?

Python None ↔ JavaScript null is a SIMILAR CONCEPT, safe to translate. JavaScript undefined is a LANGUAGE-SPECIFIC FEATURE with no Python counterpart. Don't force a false equivalence just to keep the two languages symmetrical. Real understanding means knowing where the map ends.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Empty Is Not Nothing →
← Back