자바스크립트 정의되지 않음
예
값이 없는 변수:
let x;
if (x === "undefined") {
text = "x is undefined";
} else {
text = "x is defined";
}
let x;
if (typeof x === "undefined") {
text = "x is undefined";
} else {
text = "x is defined";
}
아래에 더 많은 예가 있습니다.
정의 및 사용
정의되지 않은 속성은 변수에 값이 할당되지 않았거나 전혀 선언되지 않았음을 나타냅니다.
브라우저 지원
undefined()
ECMAScript1(ES1) 기능입니다.
ES1(JavaScript 1997)은 모든 브라우저에서 완벽하게 지원됩니다.
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
더 많은 예
예시
선언되지 않은 변수:
if (typeof y === "undefined") {
txt = "y is undefined";
} else {
txt = "y is defined";
}