0

the results why x=5,y=4
x=y+(y=x)*0
this line
x=5+(4)*0
why not? x=4+(4)*0

var x=4; 
var y=5; 
x=y+(y=x)*0; 
console.log(x); 
console.log(y);

run on chrome console

Paul
  • 26,170
  • 12
  • 85
  • 119
cx z
  • 51
  • 1
  • 4
  • See also [why the program's result is undefined?](http://stackoverflow.com/q/21979221/1048572) and [Javascript order of referencing](http://stackoverflow.com/q/18495913/1048572). `y` is overwritten *after* it is read. – Bergi May 19 '15 at 02:36

1 Answers1

2

Because y=x does not magically run before the rest of the line. JavaScript executes each bit in the expression as it comes; y comes first, and it is 5; then y = x comes, and it is 4.

Amadan
  • 191,408
  • 23
  • 240
  • 301