0

I was just trawling through the QUnit source code (1.12.0) and came across a line that confused me. I've done a bit of googling and haven't been able to come up with a reason for it.

Source: http://code.jquery.com/qunit/qunit-1.12.0.js line 520

result = !!result;

A similar thing appears further on in the code, except instead of storing the result in itself, it's storing the double negated variable in JSON.

Source: http://code.jquery.com/qunit/qunit-1.12.0.js line 957

result: !!result

As ! negates, I assume !! will negate then negate again, thus ending up with exactly what you started with. In which case, what is achieved by setting a variable equal to itself, negated twice? (Or in the latter example, returning itself negated twice instead of just returning itself.)

BSnapZ
  • 304
  • 1
  • 3
  • 13

1 Answers1

0

!! is used to convert the value to the right of it to its equivalent boolean value.

Also check this related Thread.

Community
  • 1
  • 1
Rahul Tripathi
  • 152,732
  • 28
  • 233
  • 299