JavaScript undefined Primitive
A undefined primitive represents the absence of an assigned value.
The type name is undefined.
Undefined values are one of JavaScript's 7 primitive types.
The undefined Value
The undefined primitive can only hold one value:
undefined
Type Information
The primitive type name is "undefined".
Uninitialized Variables
Variables declared without a value are undefined.
Missing Object Properties
Reading a non-existing property returns undefined.
Example
// Create a person object
const person = {name:"John"};
// Read the age property
person.age //undefined
Try it Yourself »
Missing Function Arguments
Parameters not provided gets the value undefined.
Functions Without Return Values
Functions that do not return a value return undefined.
Comparing with Undefined
Undefined vs Null
undefined and null are different values.
| Expression | Result |
|---|---|
undefined == null |
true |
undefined === null |
false |
typeof undefined |
"undefined" |
typeof null |
"object" |
Falsy Value
Undefined is a falsy value.
Example
let x;
if (x) {
document.getElementById("demo").innerHTML = "TRUE";
} else {
document.getElementById("demo").innerHTML = "FALSE";
}
Try it Yourself »
Summary
| Property | Value |
|---|---|
| Primitive Type | undefined |
| Possible Values | One (undefined) |
| Falsy | Yes |
| Object | No |