Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Detect an Undefined Object Property in JavaScript</title> </head> <body> <script> var person = { name: "Clark", age: 32, country: "United States" }; // Access an existing object property document.write(person.age); // Prints: 32 // Detect if object property is undefined if(typeof person.gender === "undefined"){ document.write("<p>This property is not defined.</p>"); } </script> </body> </html>