-1

I stumbled upon some examples of code and what I doesn't know is this x = y = z;

What does this code do?

Is this some kind of validation in javascript?

Joe
  • 15,669
  • 4
  • 48
  • 83
Mahuna
  • 21
  • 5
  • 1
    possible duplicate of [Multiple variable assignments in one row](http://stackoverflow.com/questions/11514401/multiple-variable-assignments-in-one-row) – Qantas 94 Heavy Oct 21 '14 at 09:22

3 Answers3

3

It sets every variable to the value of the right-most expression. In this case, x and y will both get the value of z.

It's an easy way to instantiate multiple variables, for example

for (var i = j = 0; i < 10; i++)

will give you a loop with 2 counters initialised - one that auto increments, and one that you can manually handle inside the loop.

Joe
  • 15,669
  • 4
  • 48
  • 83
0

No, it simply means "Set x and y to z".

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
0

No nothing like validation its simply assign value of z to y and y to x. so result is value of x , y and z are same.

Manan
  • 257
  • 1
  • 10