Created
August 2, 2016 21:52
-
-
Save fercreek/5f7f1892526e4781fe0699ec825f71f2 to your computer and use it in GitHub Desktop.
Object has a given property
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
| var ferObject = { | |
| name: 'Todd', | |
| favouriteDrink: null, | |
| cool: false | |
| }; | |
| !!ferObject.name //true | |
| !!ferObject.favouriteDrink //false | |
| !!ferObject.cool //false | |
| !!ferObject.cools //false | |
| ferObject.hasOwnProperty('name') //true | |
| ferObject.hasOwnProperty('favouriteDrink') //true | |
| ferObject.hasOwnProperty('cool') //true | |
| ferObject.hasOwnProperty('cools') //false | |
| function hasProp (obj, prop) { | |
| return Object.prototype.hasOwnProperty.call(obj, prop); | |
| } | |
| hasProp(ferObject, 'name') //true | |
| hasProp(ferObject, 'favouriteDrink') //true | |
| hasProp(ferObject, 'cool') //true | |
| hasProp(ferObject, 'cools') //false | |
| 'name' in ferObject //true | |
| 'favouriteDrink' in ferObject //true | |
| 'cool' in ferObject //true | |
| 'cools' in ferObject //false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment