HTML: Markup language
CSS: Styling language
JavaScript: Scripting language
Web APIs: Programming interfaces
All web technology
Learn web development
Discover our tools
Get to know MDN better
このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。
View in English Always switch to English
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
null という値は、意図的にオブジェクトの値が存在しないことを表します。これは JavaScript のプリミティブ値の 1 つであり、論理演算では偽値として扱われます。
null
function getVowels(str) { const m = str.match(/[aeiou]/gi); if (m === null) { return 0; } return m.length; } console.log(getVowels("sky")); // 予想される結果: 0
null 値は null というリテラルです。 null は undefined のようなグローバルオブジェクトのプロパティではありません。代わりに、 null は識別できないことを表し、変数がオブジェクトを指していないことを示します。 API においては、通常はオブジェクトが返されるところで、関連したオブジェクトがない場合に null がよく渡されます。
undefined
// foo が存在せず、定義も初期化もされていない場合: foo; // ReferenceError: foo is not defined
// foo が存在しているが、型も値も持たない場合: const foo = null; foo; // null
null や undefined をチェックする際は、等価 (==) と 厳密等価 (===) 演算子の違い に注意してください(前者では型変換が行われます)。
typeof null; // "object" (歴史的な理由で "null" ではありません) typeof undefined; // "undefined" null === undefined; // false null == undefined; // true null === null; // true null == null; // true !null; // true Number.isNaN(1 + null); // false Number.isNaN(1 + undefined); // true
Enable JavaScript to view this browser compatibility table.
NaN
void