为什么在 JavaScript 中带有一元运算符 ++ 的变量直到下一次出现在括号内时才将变量更改 1?

Why does a variable with the unary operator ++ in JavaScript not change the variable by 1 until the next appearance of the variable inside brackets?

我知道在 C、C++、Java 等语言中,foo++ 和 ++foo 是有区别的。在 JavaScript 中,没有 ++foo,并且 JavaScript 的 foo++ 通常 表现得像 C 的 ++foo:

var x = 10;
x++;
console.log(x); //11

但是这里:

var x = 0;
var w = "012345";
console.log(w[x++]); //0
console.log(w[x++]); //1

...它的行为类似于 C 的 foo++?

In JavaScript, there is no ++foo

错了。 一个前置自增运算符,它的作用是这样的:

var x = 0;
var w = "012345";
console.log(w[++x]); //1
console.log(w[++x]); //2

在 Jack Bashford 的帮助下,我想我明白了:

之所以问这个问题是因为我误解了"increment after using"的意思;我认为它的意思是在下一个语句中,它实际上是指紧跟在表达式之后。我也很困惑,因为 JavaScript 有一些关于何时使用 ++ 的约定。总之,C 的 ++ 和 JavaScript 的 ++ 工作方式相同。