I noticed that Closure Compiler compiles true and false (or 1 and 0) as !0 and !1. This doesn't make sense to me since it's twice as many characters as 1 and 0. Is there a reason for this? Is there any benefit?
Thanks.
We can clearly say that 1 is the smallest natural number and 0 is the smallest whole number. But there is no largest whole number because each number has its successor.
Numbers can be positive or negative. Positive numbers are greater than 0, and negative numbers are less than 0.
And in this sense, there is also no difference between the expressions 1/0 = 1 · 0⁻¹ and 0/0 = 0 · 0⁻¹ because 0⁻¹ simply doesn't exist.
tl;dr By axioms, any natural number can be obtained by starting with 0 and adding 1 to it a certain amount of times so 1 can't be less than 0 and it certainly isn't equal, ergo it is greater than.
1 !== true
and 0 !== false
, but !0 === true
and !1 === false
. The compiler just makes sure the type stays boolean.
Consider this example:
var a = true;
if( a === true ) {
console.log( 'True!' );
}
if( a === 1 ) {
console.log( 'You should never see this.' );
}
If you change the first line to var a = 1;
the first conditional would be false and the second true. Using var a = !0;
the script would still work correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With