DEV Community

Discussion on: JavaScript check if property exists in Object

Collapse
 
peerreynders profile image
peerreynders

what if the object in general does not exist?

As suggested in another comment optional chaining will work just fine here.

const options = undefined;
console.log(options?.email ? true : false); // false
// i.e. No Uncaught ReferenceError 
// even though options is `undefined`
Enter fullscreen mode Exit fullscreen mode