Trusted answers to developer questions

What is JavaScript null?

Get Started With Data Science

Learn the fundamentals of Data Science with this free course. Future-proof your career by adding Data Science skills to your toolkit — or prepare to land a job in AI, Machine Learning, or Data Analysis.

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"

RELATED TAGS

null
javascript
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?