Bitwise operations on non numbers

无人久伴 提交于 2019-11-29 13:29:52

According to the ES5 spec, when doing bitwise operations, all operands are converted to ToInt32 (which first calls ToNumber. If the value is NaN or Infinity, it's converted to 0).

Thus: NaN ^ 1 => 0 XOR 1 => 1

Oleg V. Volkov

ECMA-262 defines in 11.10 that arguments of binary bitwise operators are converted with ToInt32. And 9.5 that explains ToInt32 says in its first two points:

  1. Let number be the result of calling ToNumber on the input argument.
  2. If number is NaN, +0, -0, +Inf, or -Inf, return +0.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!