Is there any difference between !!!
and !
?
Found at jasmine source code in the toBeFalsy
matcher.
Results from chrome devtools
!!!undefined
true
!undefined
true
!!!null
true
!null
true
!!!0
true
!0
true
In JavaScript, it's a way to show that what you are evaluating is not a boolean but a truthy or falsy value. So for truthy/falsy values you either use !! or !!! . And for boolean values you either use ! or nothing. This is simply for readability.
The 7 falsy values are: 0 , 0n , null , undefined , false , NaN , and "" .
So, running a bang twice on a value will first change the value to the boolean opposite, and then take that returned boolean value and flip it, again, to the opposite. In short, as stated in the TL;DR, the double-bang returns the boolean true/false association of a value.
The ! symbol is used to indicate whether the expression defined is false or not. For example, !( 5==4) would return true , since 5 is not equal to 4. The equivalent in English would be not .
Is there any difference between !!! and !?
No. They are the same.
Why should I use !!! instead of ! (3 instead of 1 bang)
To annoy programmers
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