我知道这已经被问了一百万次了。但我找不到能直接回答我问题的人。只是类似的问题。
所以这个说法。
1 == !""
根据 MDN 运算符先例:https ://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence
逻辑非具有比相等更高的先例。
它还提到,赋值运算符是右结合性。因此,其他一切都必须是左结合性。
所以关于那个声明。我以为它会运行为
!"" (coerce to a bool value, flip the value)
1 == true (compare the value)
但基于进一步阅读和关联性提及。它应该从左到右运行。正确的?最终是同一件事,但它检查
1 ==
... then does the type coerce stuff
我的想法对吗?只是想确定一下。