Back to course

The Null Type: Explicit Absence of Value

JavaScript: The Complete '0 to Hero' Beginner Course

19. The null Type

null is a primitive value that represents the intentional absence of any object value. It means 'empty' or 'unknown', and it must be explicitly assigned by the developer.

Assignment

javascript let currentOrder = null; // The variable exists, but currently holds no order.

// Later, when an order is created: currentOrder = { id: 101, items: 3 };

typeof null (A Historical Error)

If you check the type of null, JavaScript returns 'object'.

javascript console.log(typeof null); // Output: object

Note: This is a famous, acknowledged bug in the original JavaScript design that cannot be fixed without breaking massive amounts of existing websites. Always remember that null is a primitive, even though typeof returns 'object'.