Skip to content

Instantly share code, notes, and snippets.

@tomarpremveer
Created December 28, 2020 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomarpremveer/29e8ae54e13ef577123c80de7e1f1268 to your computer and use it in GitHub Desktop.
Save tomarpremveer/29e8ae54e13ef577123c80de7e1f1268 to your computer and use it in GitHub Desktop.
if you're concerned only about the presence of property and not what the value is
const obj = {
name:"github",
url:"github.com"
}
//to check if the color property is present on the object or not or it's value is null
if(obj.color === null || obj.color === undefined){
console.log("this propery is not present on the obj")
}
// you can do this like this way
if(obj.color == null){ // it will cover both the case i.e obj.color == null and obj.color == undefined
console.log("this property is not present on the obj")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment