Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. JavaScript
  3. Reference
  4. Expressions and operators
  5. Increment (++)

Increment (++)

Baseline Widely available

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

Theincrement (++) operator increments (adds one to) its operand and returns the value before or after the increment, depending on where the operator is placed.

Try it

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"

Syntax

js
x++++x

Description

The++ operator is overloaded for two types of operands: number andBigInt. It firstcoerces the operand to a numeric value and tests the type of it. It performs BigInt increment if the operand becomes a BigInt; otherwise, it performs number increment.

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.

The increment operator can only be applied on operands that are references (variables and object properties; i.e., validassignment targets).++x itself evaluates to a value, not a reference, so you cannot chain multiple increment operators together.

js
++(++x); // SyntaxError: Invalid left-hand side expression in prefix operation

Examples

Postfix increment

js
let x = 3;const y = x++;// x is 4; y is 3let x2 = 3n;const y2 = x2++;// x2 is 4n; y2 is 3n

Prefix increment

js
let x = 3;const y = ++x;// x is 4; y is 4let x2 = 3n;const y2 = ++x2;// x2 is 4n; y2 is 4n

Specifications

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

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp