WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

How to Check If an Object Property is Undefined in JavaScript

Topic: JavaScript / jQueryPrev|Next

Answer: Use the strict equality operator (===)

You can use the typeof operator in combination with the strict equality operator (===) to check or detect if a JavaScript object property is undefined. Here's an example:

  • <script>
  •     var person = {
  •         name: "Clark",
  •         age: 32,
  •         country: "United States"
  •     };
  •     
  •     // Access an existing object property
  •     console.log(person.age); // Prints: 32
  •     
  •     // Detect if object property is undefined
  •     if(typeof person.gender === "undefined"){
  •         console.log("This property is not defined.");
  •     }
  • </script>

Related FAQ

Here are some more FAQ related to this topic:

Your Feedback:

We would love to hear from you, please drop us a line.