test of hasOwnProperty
also explore difference between undefined and null
by hrabinowitz
JavaScript
var myObj = {a:"b"};
console.log("myObj.a=", myObj.a);
console.log("myObj.hasOwnProperty('a')", myObj.hasOwnProperty('a'));
myObj.c = null;
console.log("myObj.c=", myObj.c);
console.log("myObj.hasOwnProperty('c')", myObj.hasOwnProperty('c'));
if (myObj['a']) {
console.log("myObj['a'] is not null");
}
if (myObj['c']) {
console.log("myObj['c'] is not null");
}
if (myObj['c'] !== undefined) {
console.log("myObj['c'] is not undefined");
}
if (myObj['c'] !== null) {
console.log("myObj['c'] is not null");
}
console.log("myObj.keys()=", Object.keys(myObj));