The increment operator (
++
) increments (adds one to) its operand and returns a value.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Operator: x++ or ++x
If used postfix, with operator after operand (for example,
x
++
), the increment operator increments and returns the value before incrementing.
If used prefix, with operator before operand (for example,
++
x
), the increment operator increments and returns the value after incrementing.
let x = 3; y = x++; // y = 3 // x = 4
let a = 2; b = ++a; // a = 3 // b = 3
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'Increment operator' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Increment (
++
)
|
Chrome 2 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 4 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 3.2 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
完整支持