null という値は、オブジェクトの値が存在しないことを表します。これは JavaScript におけるプリミティブ値の一つです。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
構文
null
説明
null 値は null というリテラルです。undefined のようなグローバルオブジェクトのプロパティではありません。代わりに、 null は識別の欠如を表し、変数がオブジェクトを指してないことを示します。API においては、通常はオブジェクトが返されるところで、関連したオブジェクトがない場合に null がよく渡されます。
// foo が存在せず、定義も初期化もされていない場合: foo; "ReferenceError: foo is not defined" // foo が存在しているが、型も値も持たない場合: var foo = null; foo; "null"
null と undefined の違い
null か undefined をチェックする際は、等価 (==) と 厳密等価 (===) 演算子の違い に注意してください(前者では型変換が行われます)。
typeof null // "object" (歴史的な理由で "null" ではありません)
typeof undefined // "undefined"
null === undefined // false
null == undefined // true
null === null // true
null == null // true
!null // true
isNaN(1 + null) // false
isNaN(1 + undefined) // true
仕様
| 仕様書 | 策定状況 | コメント |
|---|---|---|
| ECMAScript 1st Edition (ECMA-262) | 標準 | 初期定義。 |
| ECMAScript 5.1 (ECMA-262) null value の定義 |
標準 | |
| ECMAScript 2015 (6th Edition, ECMA-262) null value の定義 |
標準 | |
| ECMAScript (ECMA-262) null value の定義 |
現行の標準 |
ブラウザー実装状況
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| デスクトップ | モバイル | サーバー | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
null | Chrome 完全対応 1 | Edge 完全対応 12 | Firefox 完全対応 1 | IE 完全対応 3 | Opera 完全対応 3 | Safari 完全対応 1 | WebView Android 完全対応 1 | Chrome Android 完全対応 18 | Firefox Android 完全対応 4 | Opera Android 完全対応 10.1 | Safari iOS 完全対応 1 | Samsung Internet Android 完全対応 1.0 | nodejs 完全対応 0.1.100 |
凡例
- 完全対応
- 完全対応