Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

null is a primitive value in JavaScript that represents the intentional absence of any object value. It is a literal assigned to a variable to explicitly indicate that the identifier points to no valid memory address or holds no meaningful data.
let uninitializedObject = null;

Type Evaluation and the typeof Bug

Although null is classified as a primitive data type in the ECMAScript specification, the typeof operator evaluates it as an object. This is a well-documented historical artifact from the original implementation of JavaScript, where values were stored in 32-bit units and the type tag for objects was 000. Because null was represented as the NULL pointer (all zeros), it inherited the object type tag.
console.log(typeof null); // "object"
To strictly check if a value is null, you must use the strict equality operator (===) rather than relying on typeof.
console.log(uninitializedObject === null); // true

Type Coercion Behaviors

Boolean Context null is a falsy value. When evaluated in a boolean context (such as an if statement or logical operation), it coerces to false.
Boolean(null); // false
!!null;        // false
Numeric Context When subjected to implicit or explicit numeric coercion, null converts to 0. This is a distinct mechanical difference from undefined, which coerces to NaN.
Number(null); // 0
null + 10;    // 10
null * 5;     // 0
String Context When coerced into a string, null converts to the literal string "null".
String(null); // "null"
null + " value"; // "null value"

Equality and Comparison

JavaScript treats null and undefined as loosely equivalent, as both represent an absence of value. However, they are strictly unequal because they are of different types.
// Loose equality (type coercion allowed)
null == undefined;  // true
null == 0;          // false
null == false;      // false

// Strict equality (no type coercion)
null === undefined; // false
null === null;      // true

Prototype Chain

null sits at the absolute top of the JavaScript prototype chain. The [[Prototype]] (accessible via Object.getPrototypeOf()) of the base Object.prototype is null, signifying the end of the chain where no further inherited properties exist.
Object.getPrototypeOf(Object.prototype); // null
Master JavaScript with Deep Grasping Methodology!Learn More