Created
July 3, 2022 18:34
-
-
Save batazo/cd779d09dbc2638bef41eddce60ed54f to your computer and use it in GitHub Desktop.
Object.hasOwn()
This file contains hidden or 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 person = Object.create(null); | |
| person.age = 21; | |
| if (Object.hasOwn(person, 'age')) { | |
| console.log(person.age); // true - works regardless of how the object was created | |
| } | |
| if (person.hasOwnProperty('age')){ // throws error - person.hasOwnProperty is not a function | |
| console.log('hasOwnProperty: ', person.age); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment