What is JavaScript null?

The null value represents the intentional absence of any object value; it is one of JavaScript’s primitive values.

The null value is written with a literal ​null.

svg viewer

​Unlike undefined, null is not an identifier for a property of the global object. Instead, null expresses a lack of identification; it​ indicates that the variable does not point to any object. In APIs, null is often retrieved in a place where an object can be expected, but no object is relevant.

Code

Take a look at the example below, which highlights the use of null:

my_var;
// Executing the above statement will result in a "ReferenceError: my_var is not defined"
// my_var does not exist. It is not defined and has never been initialized:
var my_var = null;
my_var;
// my_var is known to exist now but it has no type or value:
// Executing the above statement will not throw an error"

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved