Skip to content

undefined

In JavaScript, undefined is a primitive type whose only value, also named undefined, stands for a variable, property, or result that hasn’t been given a value. The global name undefined is a read-only property of the global object, not a keyword or a literal, while null is a literal and a reserved word. Both are primitive types:

Language: JavaScript
> let total;
undefined

> total
undefined
> typeof total
'undefined'

Like every primitive, undefined is immutable and compares by value. It’s the type’s only value, so undefined === undefined and Object.is(undefined, undefined) both return true.

Where undefined Appears and typeof

JavaScript produces undefined for a declared variable without an initializer, a missing property, a missing argument, a function call that doesn’t return a value, and any expression passed to the void operator:

Language: JavaScript
> const user = { name: "Ada" };
undefined
> user.email
undefined

> function greet(name) { return name; }
undefined
> greet()
undefined

> function logName() {}
undefined
> logName()
undefined

> void 0
undefined

The typeof operator returns 'undefined' for the value and also for a name that was never declared, where reading the name directly throws a ReferenceError. The exception is a let, const, or class name used before its declaration, where typeof throws a ReferenceError too:

Language: JavaScript
> typeof missingName
'undefined'
> missingName
Uncaught ReferenceError: missingName is not defined

Reading a property of undefined throws a TypeError.

Comparing and Converting undefined

Loose equality treats undefined and null as equal to each other and to nothing else in standard JavaScript, so value == null matches both values, while value === undefined matches only undefined. Other conversions follow the type coercion rules, and undefined is falsy:

Language: JavaScript
> undefined == null
true
> undefined === null
false
> undefined == 0
false

> Number(undefined)
NaN
> String(undefined)
'undefined'
> Boolean(undefined)
false

Common undefined Gotchas

Default parameter values apply when an argument is undefined, either missing or passed explicitly, but not when it’s null:

Language: JavaScript
> function welcome(name = "guest") { return `Hello, ${name}!`; }
undefined

> welcome(undefined)
'Hello, guest!'
> welcome(null)
'Hello, null!'

JSON.stringify() drops object properties whose value is undefined and writes undefined array elements as null:

Language: JavaScript
> JSON.stringify({ name: "Ada", email: undefined })
'{"name":"Ada"}'

> JSON.stringify([1, undefined, 3])
'[1,null,3]'

A property set to undefined and a missing property read the same, so telling them apart takes the in operator, which also finds inherited properties, or Object.hasOwn(), which checks only the object’s own properties:

Language: JavaScript
> const settings = { theme: undefined };
undefined

> settings.theme === settings.fontSize
true

> "theme" in settings
true
> "fontSize" in settings
false

Assigning to the global undefined is silently ignored in sloppy mode and throws a TypeError in strict mode. Because undefined isn’t a reserved word, though, a local variable or parameter can still use undefined as its name and shadow the global value.

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Nov. 4, 2026