Movatterモバイル変換


[0]ホーム

URL:


  1. 給開發者的 Web 技術文件
  2. JavaScript
  3. JavaScript 參考文件
  4. 運算式與運算子
  5. 遞增運算子(++)

此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。

View in EnglishAlways switch to English

遞增運算子(++)

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

遞增運算子(++)遞增(加一)它的運算元並將結果回傳。

嘗試一下

let x = 3;const y = x++;console.log(`x:${x}, y:${y}`);// Expected output: "x:4, y:3"let a = 3;const b = ++a;console.log(`a:${a}, b:${b}`);// Expected output: "a:4, b:4"

語法

js
x++++x

詳細說明

若將遞增運算子作為後綴(例如x++),則會先回傳原本的值,再進行遞增。

若作為前綴(例如++x),則會先進行遞增,再將遞增後的結果回傳。

範例

遞增運算子置於後綴

js
let x = 3;y = x++;// y = 3// x = 4

遞增運算子置於前綴

js
let a = 2;b = ++a;// a = 3// b = 3

規範

Specification
ECMAScript® 2026 Language Specification
# sec-postfix-increment-operator

瀏覽器相容性

參見

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp