[Javascript] ++operation

Zhentiw發表於2024-11-24

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 ++aand 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

相關文章