Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptIncrement(+ +) Arithmetic Operator in JavaScript

Increment(+ +) Arithmetic Operator in JavaScript

JavaScript increment(+ +) operator is used to increase the value of the variable by one. The value returned from the operand depends on whether the increment operator was on the left(prefix increment) or right(postfix increment). If the operator is used before the operand then the value is increased by one and then returned but if the operator is after the operand then the value is first returned and then incremented. 

The increment operator can only be used on references that is the operator can only be applied to variable and object properties. Also, the increment operator cannot be chained

Syntax:

a++
OR
++a

Example 1: In this example, we will see the value returned when the increment operator is applied after the operand(postfix increment).

Javascript




let x = 10;
console.log(x++);
console.log(x);


Output: We can observe that first the value is returned and then incremented.

10
11

Example 2: In this example, we will see the values returned when the operator is applied before the operand(prefix increment).

Javascript




let x = 10;
console.log(++x);
console.log(x);


Output: Here the value is first incremented and then returned.

11
11

Supported Browsers:

  • Chrome
  • Edge
  • Firefox
  • Opera
  • Safari

We have a complete list of Javascript Arithmetic operators, to check those please go through this JavaScript Arithmetic Operators article.

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments