I am reading through the Mozilla Manual on JavaScript, and I come to this point in my reading, Boolean object. I can\'t see a single use for them. What\'s their point? Why w
Boolean.prototype.bang = function() {
return !this.valueOf();
}
true.bang(); // false
Everything in JavaScript is an object. But at the same time we also have primitives. It's really confusing, just don't overthink it.
Perhaps because JavaScript objects are extensible in ways that primitives aren't? (I'm just guessing here, I've never had a need for Boolean.
JavaScript language design has quite many dusty corners, and the Boolean is one of them; it is not used in practice.
This:
var a = [];
alert(a instanceof Array);
will tell you "true". But this:
var b = true;
alert(b instanceof Boolean);
for some reason will show "false".
In short: forget about it.