23 ms·
This is true in a whole slew of languages. Here's Ruby: irb(main):001:0> 3 => 3 irb(main):002:0> !3 => false irb(main):003:0> !!3 => true And here
by kibwen 13y ago
This is true in a whole slew of languages. Here's Ruby:
irb(main):001:0> 3
=> 3
irb(main):002:0> !3
=> false
irb(main):003:0> !!3
=> true
And here's C:
#include<stdio.h>
main() {
printf("%d %d %d", 3, !3, !!3); // 3 0 1
}
Even the venerable and (relatively) strongly-typed Python falls prey to this:
>>> 3
3
>>> not 3
False
>>> not not 3
True
Basically any language where the ! operator coerces to boolean (or in C's case, the nearest approximation to boolean). Though personally I tend to agree that implicit coercions are undesirable, don't be too quick to cry JAVASCRIPT WUT, as it has quite a lot of precedence. :)