What's the output of following code:
let a = 1;
const b = a + ++a * a++;
In Javascript, the code always run from lef to right.
Both ++a
and a++
are expression. Every expression has return value.
a++
returns 1, then a
was assigned to 2
let a = 1;
const b = a + ++a * a++;
// const b = 1 + 2 * 2
// let a = 3