简体   繁体   English

JavaScript中a = b == c的顺序优先级是什么?

[英]What is the order precedence of a = b == c in JavaScript?

var clicked = $(event.currentTarget || target);
var clickedIsActive = clicked[0] == this.active[0];

I'm fairly new to js, and while attempting to read through some jQuery code, I came across the above section. 我是js的新手,在尝试阅读一些jQuery代码时,我遇到了上面的部分。

What is the precedence for the second line? 第二行的优先顺序是什么?

Is it: 是吗:

var clickedIsActive = (clicked[0] == this.active[0]);

Or is it something else? 或者是别的什么?

Thank you. 谢谢。

Yes, the rightmost side of an assignment is evaluated first. 是的,首先评估作业的最右侧。

clickedIsActive is assigned the result of the expression clicked[0] == this.active[0] . clickedIsActive分配了clicked[0] == this.active[0]的表达式的结果。

var clickedIsActive = clicked[0] == this.active[0];

clickedIsActive是比较clicked[0] == this.active[0]的结果,所以clicked[0] == this.active[0]必须先进行比较。

I think you might be confusing the = with the == . 我想你可能会混淆=== They're not the same thing so this is very much like comparing apples with oranges. 它们不是一回事,所以这非常类似于将苹果与橙子进行比较。

= is an assignment. =是一项任务。 == is a "is equal" comparison that will only return true or false . ==是一个“相等”的比较,只会返回truefalse

Misunderstanding or not, your transcode is correct. 是否存在误解,您的转码是正确的。 The right side of an assignment is parsed before the actual assignment. 在实际分配之前解析赋值的右侧。 The Javascript VM needs to know what it's assigning something as before it can save it. Javascript VM需要知道它之前分配的东西,因为它可以保存它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM