null

by 3 contributors:

This article is in need of a technical review.

This article is in need of an editorial review.

null という値は null ないしは「空」の値を表す JavaScript のリテラルで、言い換えれば、オブジェクトの値が存在しないことを表します。これは JavaScript におけるプリミティブ値の一つです。

構文

null

説明

null 値は(undefined のようなグローバルオブジェクトのプロパティではなく)リテラルの一つです。多くの API では、通常はオブジェクトが返されるところで、関連したオブジェクトがない場合に null がよく渡されます。null か undefined をチェックする際は、等値演算子 (==) と同値演算子 (===) の違い に注意してください(前者では型変換が行われます)。

// foo が存在せず、定義も初期化もされていない場合:
> foo
"ReferenceError: foo is not defined"

// foo が存在しているが、型も値も持たない場合:
> var foo = null; foo
"null"

nullundefined の違い

typeof null        // object (ECMAScript のバグ、本来は null となるべき)
typeof undefined   // undefined
null === undefined // false
null  == undefined // true

仕様

仕様 状況 コメント
ECMAScript 1st Edition (ECMA-262) Standard 初期定義。
ECMAScript 5.1 (ECMA-262)
The definition of 'null value' in that specification.
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'null value' in that specification.
Standard  

ブラウザ互換性

機能 Chrome Firefox (Gecko) Internet Explorer Opera Safari
基本サポート (有) (有) (有) (有) (有)
機能 Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
基本サポート (有) (有) (有) (有) (有) (有)

関連項目

ドキュメントのタグと貢献者

Contributors to this page: x2357, teoli, chikoski
最終更新者: x2357,
サイドバーを隠す