Looking through the source code of one of our projects, I've found some amount of places where we're using three exclamation marks in conditional statements, like so:
if (!!!someVar) { // ... }
Now, I understand that this isn't some kind of rarely used operator, it's just three negations in a row, like !(!(!someVar)))
. I don't understand what's the use of it - in my opinion it can safely be replaced with single exclamation mark. Following are my attempts to find a case when !!!a
isn't equal to !a
(taken straight from the google chrome console):
var a = '' "" !!!a === !a true a = 'string' "string" !!!a === !a true a = null null !!!a === !a true a = 12 12 !!!a === !a true a = {b: 1} Object {b: 1} !!!a.c === !a.c // a.c is undefined here true a = [] [] !!!a === !a true a = [1,2] [1, 2] !!!a === !a true
Am I missing some rare (or obvious) case?
In formal text it means you didn't do enough with the words to sell the reader in being exclaimed. In informal writing it means you're really trying to sell the statement at shocking.
3. In informal writing, multiple exclamation points are sometimes used to indicate stronger emphasis or emotion. However, in formal writing only one is necessary. 4.
Overuse of the exclamation point, though (e.g., using them on back to back sentences) can backfire. For example, when a person uses “too many” exclamation points, they're perceived as desperate. When used properly, though, exclamation marks can be particularly valuable for communicating gratefulness.
So the third use (!! x) turns the "falsey" value into a true boolean. ... with that in mind, the third exclamation point makes a TRUE negation of the original value (a negation of the "true boolean" value).
There is no difference between !a
and !!!a
, since !!!a
is just !!(!a)
and because !a
is a boolean, !!(!a)
is just its double negation, therefore the same.
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