EtienneG
EtienneG

Reputation: 320

Is there an interest to use double boolean negation?

As a beginner in Javascript, I have a question which may seem a bit weird. I am using an external lib I found on the web in which I found the code below :

if('useHoles' in c){
   this.config.useHoles = !!c.useHoles;
}

Is there an interest to use the double exclamation mark or is it just some clumsy code ?

Couldn't find any answer yet so I guess I can just remove them but I wanted to be 100% sure.

Upvotes: 2

Views: 446

Answers (1)

With the double ! you force an object to return something that is "boolean-able", even if null or something else, that can be evaluated as bool true or false.

Upvotes: 3

Related Questions