7

I know that !!variable will convert variable into a boolean value and the function Boolean(), according to the ecma262 spec, will also perform a type conversion by calling ToBoolean(value).

My question is: what's the difference? Is !! better in performance than Boolean() ?

Joseph Quinsey
  • 9,553
  • 10
  • 54
  • 77
aztack
  • 4,376
  • 5
  • 32
  • 50

1 Answers1

9

They are the same, as the ! operator will call ToBoolean() internally on its operand, and then flip that returned value, while Boolean() will call ToBoolean() internally on its argument.

alex
  • 479,566
  • 201
  • 878
  • 984