0

enter code hereI have often seen this --

if(!!somevalue)

I don't know why do people use !! and instead they could just write this --

if(somevalue)

because as far as I know

somevalue === !!somevalue

I do not have any issue but I am just curious as in what is the reason behind it?

Cute_Ninja
  • 4,742
  • 4
  • 39
  • 63
  • they want a boolean as a result, so they make the expression a boolean. don't look for reason behind what a lot of people do in JS. i've even seen if(Boolean(val)===true)! at least they used a strong equality compare right? old-fashioned coders often don't understand the way JS coerces types, and they are used to spelling it out. maybe to them it's more readable. – dandavis Aug 19 '14 at 23:55
  • In an `if` statement seems rather useless. – elclanrs Aug 19 '14 at 23:55

0 Answers0