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
null;
Example
Let's define the variable value:
let res = null;
console.log(res);
The code execution result:
null
Example
The null value is returned by
methods for searching DOM elements
if the element was not found:
let res = document.querySelector('#elem');
console.log(res);
The code execution result:
null