3

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,185
  • 10
  • 53
  • 75
aztack
  • 4,206
  • 5
  • 29
  • 49

1 Answers1

4

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
  • 460,746
  • 196
  • 858
  • 974