ในการตรวจสอบว่ามีการกำหนดฟังก์ชัน JavaScript หรือไม่ ให้ตรวจสอบด้วย "undefined"
ตัวอย่าง
คุณสามารถลองเรียกใช้ตัวอย่างต่อไปนี้เพื่อตรวจสอบว่ามีการกำหนดฟังก์ชันหรือไม่ใน JavaScript -
<!DOCTYPE html>
<html>
<body>
<script>
function display() {
alert("Hello World!");
}
if ( typeof(display) === 'undefined') {
document.write('undefined');
} else {
document.write("Function is defined");
}
</script>
</body>
</html>