null value

The null value means "nothing", i.e. the absence of an object or element. When performing logical operations, it is equivalent to a false statement or false. JavaScript has a similar undefined value that denotes the absence of a value. The difference is that null denotes an intentional absence (explicitly written in a code), while undefined is simply the absence of any information about the element type and its value.

Syntax

javascriptnull;

Example

Let's define the variable value:

javascriptlet res = null;
console.log(res);

The code execution result:

javascriptnull

Example

The null value is returned by methods for searching DOM elements if the element was not found:

javascriptlet res = document.querySelector('#elem');
console.log(res);

The code execution result:

javascriptnull

See also

  • the true value
    that indicates that the element value is true
  • the false value
    that indicates that the element value is false
  • the undefined value
    that denotes that the element value is "undefined"