null
Baseline
Widely available
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 ã¤ã§ãããè«çæ¼ç®ã§ã¯å½å¤ã¨ãã¦æ±ããã¾ãã
試ãã¦ã¿ã¾ããã
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 ã¨ãããªãã©ã«ã§ãã null 㯠undefined ã®ãããªã°ãã¼ãã«ãªãã¸ã§ã¯ãã®ããããã£ã§ã¯ããã¾ããã代ããã«ã null ã¯èå¥ã§ããªããã¨ã表ãã夿°ããªãã¸ã§ã¯ããæãã¦ããªããã¨ã示ãã¾ãã API ã«ããã¦ã¯ãé常ã¯ãªãã¸ã§ã¯ããè¿ãããã¨ããã§ãé¢é£ãããªãã¸ã§ã¯ãããªãå ´åã« null ãããæ¸¡ããã¾ãã
// foo ãåå¨ãããå®ç¾©ãåæåãããã¦ããªãå ´å:
foo; // ReferenceError: foo is not defined
// foo ãåå¨ãã¦ããããåãå¤ãæããªãå ´å:
const 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
Number.isNaN(1 + null); // false
Number.isNaN(1 + undefined); // true
仿§æ¸
| Specification |
|---|
| ECMAScript® 2027 Language Specification> # sec-null-value> |