JavaScript: Difference Between null vs undefined

By Xah Lee. Date: .

undefined is the value when a variable isn't assigned, property doesn't exist, value of function that doesn't have return statement, value of function args not given, out of bound array access, etc. See: undefined .

null is the value of a object's internal slot [[prototype]] when the object doesn't have a parent. [see Prototype and Inheritance]

JavaScript the language does not restrict how you use null or undefined.

In general, you can pass undefined as argument in function call, as if no argument is given. Such as in setUserData("John", undefined, 23). (But exact behavior of the function depends on the function.)

You can also use null as initial value of a variable.

JavaScript Special Literals

JavaScript in Depth

JS Obj Reference

Global Object

Special Objects

Static Objects

Primitive Wrapper

Constant Literals

Simple Functions

Error Objects