显示警告 我如何使用 ^
Show's an Warning How can i use ^
是
err^d === null
与
相同
err === null && d === null
以上两个条件在应用时输出相同的结果。
但 eslint 总是显示
unexpected use of '^' no-bitwise
ESLint 默认禁止按位运算符,因为它们通常是错误的(即你的意思是 &&
但输入的是 &
)。您可以通过将 no-bitwise
设置为 allow
来禁用此行为。 See the documentation.
话虽如此,这不会如您所愿。按位运算符将两个操作数强制转换为数字。意思是null
转为0
,false
,undefined
,空数组,只包含0
s的数组,NaN
,大多数(也许是所有)对象。您并不是真的在此处测试 null
。 See the ECMAScript spec for demonstration of this.
是
err^d === null
与
相同err === null && d === null
以上两个条件在应用时输出相同的结果。
但 eslint 总是显示
unexpected use of '^'
no-bitwise
ESLint 默认禁止按位运算符,因为它们通常是错误的(即你的意思是 &&
但输入的是 &
)。您可以通过将 no-bitwise
设置为 allow
来禁用此行为。 See the documentation.
话虽如此,这不会如您所愿。按位运算符将两个操作数强制转换为数字。意思是null
转为0
,false
,undefined
,空数组,只包含0
s的数组,NaN
,大多数(也许是所有)对象。您并不是真的在此处测试 null
。 See the ECMAScript spec for demonstration of this.