cx z
cx z

Reputation: 51

Javascript order of execution of assignment expressions

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

Upvotes: 0

Views: 96

Answers (1)

Amadan
Amadan

Reputation: 198388

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.

Upvotes: 2

Related Questions