Baseline Widely available
ã°ãã¼ãã«ã® undefined
ããããã£ã¯ããªããã£ãå¤ã® undefined
ã表ãã¾ãããã㯠JavaScript ã«ãããããªããã£ãåã®ä¸ã¤ã§ãã
function test(t) {
if (t === undefined) {
return "Undefined value!";
}
return t;
}
let x;
console.log(test(x));
// Expected output: "Undefined value!"
æ§æ 解説
undefined
ã¯ãã°ãã¼ãã«ãªãã¸ã§ã¯ãã®ããããã£ã§ããããªãã¡ã°ãã¼ãã«ã¹ã³ã¼ãå
ã®å¤æ°ã§ãã undefined
ã®åæå¤ã¯ããªããã£ãå¤ã§ãã undefined
ã§ãã
æè¿ã®ãã©ã¦ã¶ã¼ (JavaScript 1.8.5 / Firefox 4 以é) ã§ã® undefined
ã¯ã ECMAScript 5 仿§ã«ãããè¨å®ä¸å¯ãæ¸è¾¼ä¸å¯ã®ããããã£ã¨ãªãã¾ãã (ããã§ãªãå ´åã§ãã䏿¸ãã¯é¿ãã¦ãã ããã)
ã¾ã å¤ã代å
¥ããã¦ããªã夿°ã¯ undefined
åã¨ãªãã¾ããè©ä¾¡ãããã¨ãã¦ãã夿°ã«å¤ã代å
¥ããã¦ããªãå ´åãã¡ã½ãããæã undefined
ãè¿ãã¾ããå¤ã return
ããªã颿°ã undefined
ãè¿ãã¾ãã
ã¡ã¢: ã°ãã¼ãã«ã¹ã³ã¼ã以å¤ã®ã¹ã³ã¼ãã§ã¯ undefined
ãèå¥å (夿°å) ã¨ãã¦ä½¿ããã¨ãã§ãã¾ãã (undefined
ã¯äºç´èªã§ãªããã)ãã³ã¼ãã®ç®¡çããããã°ãå°é£ã«ãªãããããããã§ãã¾ããã
//ãããªãã¨ã¯ããªããã¨ï¼
// "foo string" ããã°åºåãã
(function () {
var undefined = "foo";
console.log(undefined, typeof undefined);
})();
// "foo string" ããã°åºåãã
(function (undefined) {
console.log(undefined, typeof undefined);
})("foo");
ä¾ å³å¯ç価㨠undefined
undefined
ã¨å³å¯ç価ã»éç価æ¼ç®åã使ã£ã¦ã夿°ã«å¤ãããã調ã¹ããã¨ãã§ãã¾ããæ¬¡ã®ã³ã¼ãã§ã¯ã夿° x
ãå®ç¾©ããã¦ããªãããã if
æã¯ true ã«è©ä¾¡ããã¾ãã
var x;
if (x === undefined) {
// ããã®æã¯å®è¡ããã
} else {
// ããã®æã¯å®è¡ãããªã
}
ã¡ã¢: ããã§ã¯ãæ¨æºã®ç価æ¼ç®åã§ã¯ãªãå³å¯ç価æ¼ç®åã使ããªãã¨ããã¾ãããå³å¯ç価æ¼ç®åã¨ã¯éãã x == undefined
ã¯ã x
ã null
ã§ãããã©ããããã§ãã¯ããããã§ãã null
㯠undefined
ã¨çããããã¾ããã
詳ããã¯ãæ¯è¼æ¼ç®åãåç §ãã¦ãã ããã
typeof æ¼ç®å㨠undefined代ããã«ã typeof
ã使ç¨ãããã¨ãã§ãã¾ãã
var x;
if (typeof x === "undefined") {
// ããã®æã¯å®è¡ããã
}
typeof
ã使ãçç±ã®ä¸ã¤ã¨ãã¦ããã¡ãã¯å¤æ°ã宣è¨ããã¦ããªãã¦ãã¨ã©ã¼ã«ã¯ãªãã¾ããã
// ç´åã¾ã§ x ã¯å®£è¨ããã¦ããªã
if (typeof x === "undefined") {
// ã¨ã©ã¼ãªãã§ true ã¨è©ä¾¡ããã
// ããã®æã¯å®è¡ããã
}
if (x === undefined) {
// ReferenceError ãçºç
}
ããããããä¸ã¤ã®é¸æè¢ãããã¾ãã JavaScript ã¯éçã«ã¹ã³ã¼ããããè¨èªãªã®ã§ã夿°ã宣è¨ããã¦ãããã©ãããç¥ãã«ã¯ããããå«ã¾ããã³ã³ããã¹ãã§å®£è¨ããã¦ãããã©ãããè¦ããã¨ã§èªã¿åããã¨ãã§ãã¾ãã
ã°ãã¼ãã«ã¹ã³ã¼ãã¯ã°ãã¼ãã«ãªãã¸ã§ã¯ãã«çµã³ã¤ãããã¦ããã®ã§ãã°ãã¼ãã«ã³ã³ããã¹ãã«å¤æ°ãåå¨ãããã©ããã®ãã§ãã¯ã¯ãã°ãã¼ãã«ãªãã¸ã§ã¯ãã«ããããã£ãåå¨ãããã¨ãã in
æ¼ç®åã使ç¨ãã¦ãã§ãã¯ãããã¨ã§è¡ããã¨ãã§ãã¾ãã
if ("x" in window) {
// x ãã°ãã¼ãã«ã«å®ç¾©ããã¦ããå ´åã®ã¿ãããã®æãå®è¡
}
void æ¼ç®å㨠undefined
3 ã¤ç®ã®æ¹æ³ã¨ãã¦ãvoid
æ¼ç®åãããã¾ãã
var x;
if (x === void 0) {
// ããã®æã¯å®è¡ããã
}
// ç´åã¾ã§ y ã¯å®£è¨ããã¦ããªã
if (y === void 0) {
// ReferenceError: y is not defined ãçºç
}
仿§æ¸ ãã©ã¦ã¶ã¼ã®äºææ§ é¢é£æ
å ±
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4