views:

79

answers:

3
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.

What is the precedence for the second line?

Is it:

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

Or is it something else?

Thank you.

+6  A: 

Yes, the rightmost side of an assignment is evaluated first.

clickedIsActive is assigned the result of the expression clicked[0] == this.active[0].

Jacob Relkin
+2  A: 
var clickedIsActive = clicked[0] == this.active[0];

clickedIsActive is the result of comparing clicked[0] == this.active[0] so clicked[0] == this.active[0] would have to be compared first.

Kevin
A: 

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.

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.

Oli