JavaScript Data Types: null vs undefined

By: Dusty Arlia
Published on Monday, September 30, 2013, 08:37 AM
Last Updated on Sunday, July 12, 2015 at 3:25 PM
Total Updates: 4

Characteristic null undefined
Is... undefined is a predefined global variable.
Gets initialized? No. Yes. The undefined variable gets assigned the undefined value.
Is it a JavaScript keyword? Yes. No (global variable).
The typeof operator returns... the string object. undefined.
Members of this data type: It is the sole member of its own data type. It is the sole member of its own data type.
This returned value means... no value for numbers, strings, and objects. no value. It is the value of a variable that has not yet been initialized. It is also the value you get when you query the value of an object property or array element that does not exist.
The value... - undefined is returned by functions that do not have a return value.

- undefined is the value assigned to function parameters for which no argument is assigned.
Uses Use null to represent a normal expected absence of value. You should use the value null most of the time if you need to assign one of these values to a variable, property, or function argument. Use undefined to represent an unexpected absense of value.
In ECMAScript 3... undefined is a read/write and it can be set to any value.
In ECMAScript 5... undefined is a read-only (corrected ECMAScript 3's mistake).
Both indicate an absence of value.
Equal when compared with the == operator
The values of each data type evaluate to false
Neither data type has any properties or methods
Trying to access a property or method using . or [] on a null or undefined value, throws a TypeError
There are no wrapper objects for null or undefined values.
Both null and undefined don't have constructors.