In JS a Boolean has 4 states.
true
false
undefined (where the key is set to undefined)
undefined (where the key doesn’t exist on the object)
if (obj.value === true) {
console.log(1);
} elseif (obj.value === false) {
console.log(2);
} elseif ("value" in obj) { // key "value" is in the obj, but it is set to undefined
console.log(3);
} else { // key "value" is not in object
console.log(4);
}
Please add a trigger warning to this in the future, this is too scary
In JS a Boolean has 4 states.
true
false
undefined (where the key is set to undefined)
undefined (where the key doesn’t exist on the object)
if (obj.value === true) { console.log(1); } else if (obj.value === false) { console.log(2); } else if ("value" in obj) { // key "value" is in the obj, but it is set to undefined console.log(3); } else { // key "value" is not in object console.log(4); }
You’re welcome.
deleted by creator