English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript null null value

 JavaScript Global Properties/Function

null valuerepresenting the intentional absence of any object value.

It is JavaScript'sOne of the primitive types.

The null value is not an identifier for a global object property, such as undefined. Instead, null represents a lack of identification, indicating that the variable does not point to any object.

Syntax:

null
var str;
if (str == null) {
   // str is null
}
   // str is not null
}
Test and see‹/›

The difference between null and undefined

The values of null and undefined are equal, but the types are different.

When checking null or undefined, please note the difference between equals (==) and identity (===) operators, as the former performs type coercion.

typeof null  // "object" (due to legacy reasons, it is not "null")
typeof undefined // "undefined"
null == undefined// true
null === undefined   // false
Test and see‹/›

Browser Compatibility

All browsers fully support null values:

Value
nullYesYesYesYesYes

Technical Details

JavaScript Version:ECMAScript 1

More Examples

If the given string does not contain [aeiou] letters, the getVowels() function will return 0:

function getVowels(str) {
   var x = str.match(/[aeiou]/gi);
   if (x === null) {
      return 0;
   }
   return x.length;
}
Test and see‹/›

 JavaScript Global Properties/Function