javascript - difference between if (!!variable), and, if (variable)? -


this question has answer here:

is there difference (in js) between using double negative !! , not using @ all?

for example

if (!!variable){... vs. if (variable){...

i know there times i've gotten warning using 2nd method..

when should each used? , when each throw warning in console? (for variables, objects, arrays etc.)

thanks!!

there difference assigning it, not using in conditional statement. reason !! used because first ! convert variable truthy evaluation , not it. "hello" becomes true, negated, becomes false, , second ! negate false, resulting in true. can desirable when trying obtain thruthy value variable. however, there not gained doing in if statement.


Comments