1var person={"name":"Billy","age":20}
2person.hasOwnProperty("name"); // true
3person.hasOwnProperty("sex"); // false
1"key" in obj // true, regardless of the actual value
2
3If you want to check if a key doesn't exist, remember to use parenthesis:
4!("key" in obj) // true if "key" doesn't exist in object
5!"key" in obj // ERROR! Equivalent to "false in obj"
6
7Or, if you want to particularly test for properties of the object instance (and not inherited properties), use hasOwnProperty:
8obj.hasOwnProperty("key") // true
1!("key" in obj) // true if "key" doesn't exist in object
2!"key" in obj // ERROR! Equivalent to "false in obj"
3
1var obj = { key: undefined };
2obj["key"] !== undefined // false, but the key exists!