null
試してみましょう
構文
null
解説
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
仕様書
No specification found
No specification data found for javascript.builtins.null
.
Check for problems with this page or contribute a missing spec_url
to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.
ブラウザーの互換性
No compatibility data found for javascript.builtins.null
.
Check for problems with this page or contribute missing data to mdn/browser-compat-data.