This JavaScript code will result in -11, but I don't know what is the mathematical process.
let x = 2;
let y = 4;
console.log(x -= y += 9)
This JavaScript code will result in -11, but I don't know what is the mathematical process.
let x = 2;
let y = 4;
console.log(x -= y += 9)
Break down each step:
y += 9
y = y + 9
y = 4 + 9
y = 13
x -= y
x = x - y
x = 2 - 13
x = -11
It might be helpful to think of this as
let x = 2;
let y = 4;
let z = x -= (y += 9);
console.log(z);
We're setting the term in the parantheses to y += 9 (which is 13), then setting z to x -= 13, which is -11.
That being said, this is a horrible way of writing this!
The execution start with y=y+9 which is 4+9=13 then it evaluates x=x-y which is 2-13=-11 so answer is -11.