คำอธิบาย
ตรวจสอบว่า parameter เป็น undefined หรือไม่ ถ้าใช่ กำหนดค่าเริ่มต้นใหม่
ตัวอย่างโค้ด
function showValue(value) {
if (value === undefined) {
value = 100000;
}
return value;
}
console.log("The value=" + showValue(300));
console.log("The value=" + showValue(undefined));
วิธีรัน
node fileName.js
ผลลัพธ์
The value=300 The value=100000