Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. JavaScript
  3. Reference
  4. Expressions and operators
  5. null

null

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

Thenull keyword refers to thenullprimitive value, which represents the intentional absence of any object value.

Try it

function getVowels(str) {  const m = str.match(/[aeiou]/gi);  if (m === null) {    return 0;  }  return m.length;}console.log(getVowels("sky"));// Expected output: 0

Syntax

js
null

Description

The keywordnull is a literal for thenull value. Unlikeundefined, which is a global variable,null is not an identifier but a syntax keyword.

null has the following behaviors:

JavaScript is unique to have two nullish values:null andundefined. Semantically, their difference is very minor:undefined represents the absence of a value, whilenull represents the absence of anobject. For example, the end of theprototype chain isnull because the prototype chain is composed of objects;document.querySelector() returnsnull if it doesn't match, because had it matched, the result would be an object. If you are designing an API, you should likely acceptnull andundefined as equivalent inputs, because many codebases have stylistic rules about when to usenull orundefined by default.

Examples

Difference betweennull andundefined

When checking fornull orundefined, beware of thedifferences between equality (==) and identity (===) operators, as the former performs type-conversion.

js
typeof null; // "object" (not "null" for legacy reasons)typeof undefined; // "undefined"null === undefined; // falsenull == undefined; // truenull === null; // truenull == null; // true!null; // trueNumber.isNaN(1 + null); // falseNumber.isNaN(1 + undefined); // true

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-null-value

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp