Created
December 28, 2020 07:08
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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