Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mohamedkhallouq
GitHub Repository: mohamedkhallouq/content
Path: blob/main/files/en-us/web/javascript/reference/operators/increment/index.md
6520 views
---
title: Increment (++) slug: Web/JavaScript/Reference/Operators/Increment page-type: javascript-operator browser-compat: javascript.operators.increment
---

{{jsSidebar("Operators")}}

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

{{EmbedInteractiveExample("pages/js/expressions-increment.html")}}

Syntax

x++ ++x

Description

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. valid assignment targets). ++x itself evaluates to a value, not a reference, so you cannot chain multiple increment operators together.

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

Examples

Postfix increment

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

Prefix increment

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

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also