The "if" condition evaluates to false if the value is falsy (null, undefined, 0, NaN, '')
Thus, when checking if a property exists, could use "in" method (check both own and prototype properties) to check:
var person = {};
console.log("name" in person); //false;
If only wants to see if it is its own property, using hasOwnProperty();
No comments:
Post a Comment