In Javascript - value =!!value
love2dev.com
love2dev.com
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. :)I'm sure the mods will change the title to the one from the actual post: "What the Heck is !! in JavaScript?" which is a much better title.
Note: their example of a similar piece of code is not identical, as it won't cast values like null to false. I think the best example of a clear equivalent would be:
value = value ? true : false;Compare:
> typeof Boolean(1)
'boolean'
> typeof new Boolean(1)
'object'