1
Consider the following code:
if (!!!window.customElements) {
execPolyfill();
}
What is the function of the 3 exclamation points before the expression window.customElements
where only 1 would have the same effect?
1
Consider the following code:
if (!!!window.customElements) {
execPolyfill();
}
What is the function of the 3 exclamation points before the expression window.customElements
where only 1 would have the same effect?
Browser other questions tagged javascript logic
You are not signed in. Login or sign up in order to post.
Triple denial denies so denied!!!
– Jefferson Quesado
@Jeffersonquesado I realized but what the reason to use this, it was not enough to use only 1?
– Filipe Moraes
I can only think that the intention is to improve readability.
– Pablo Almeida
It’s legibility, look at this related question in Soen. The value will always be the same as
!window.customElements
– Isac
@Isac it was nice to put this response of Soen here in English.
– Filipe Moraes
@Filipemoraes agree with you. I don’t know if whoever made the code heard of it "to take the boolean value of a falsy in javascript, use the double negation" and applied this principle to catch the reverse, hence the triple. We have two classes of denial operators involved here: falsy => boolean and boolean ==> boolean. The two leftmost denials (therefore the last to be operated on) are of the second type, whereas only the first negation (glued to the result of the function call) does the job of taking a falsy and turn into a boolean. How to deny a boolean is idempotent...
– Jefferson Quesado
The question is related to this but it’s slightly different, so I don’t agree to be marked as [duplicated].
– Filipe Moraes
There’s no difference between
!a
and!!!a
-> https://stackoverflow.com/a/25318045/6510304– Don't Panic