Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Something = Something = Something... What?

Tags:

javascript

I'm reading some code and I see a comparison that's laid out like this:

a = b = c

Seeing as how searching Javascript about equal or comparison yields remedial results, anyone care to explain what's going on?

EDIT: These are all objects or object properties that we're talking about here, should have specified.

DOUBLE EDIT: This is inside of an Object.defineProperties() block.

like image 834
AlbertEngelB Avatar asked Dec 04 '22 14:12

AlbertEngelB


1 Answers

= is an operator. It takes two arguments: a variable reference and an expression. It assigns the value of the expression to the variable, and returns the assigned value.

As a result, you can chain them and it equates to this:

a = (b = c)

In other words, assign b to the value of c, then assign that value to a also.

like image 106
Niet the Dark Absol Avatar answered Dec 28 '22 02:12

Niet the Dark Absol