JavaScript ไม่ได้กำหนด
ตัวอย่าง
ตัวแปรที่ไม่มีค่า:
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";
}