JavaScript auto increment variable | Example code

Incremental operator ++ used to increase the existing variable value by 1 (x = x + 1). Increment operators in JS programming used in For Loop, While loop, and Do While loops.

  • ++i (Pre increment): It will increment the value of i even before assigning it to the variable i.
  • i++ (Post-increment): The operator returns the variable value first (i.e, i value) then only i value will incremented by 1.

JavaScript auto increment variable example code

Here is HTML example code of auto increment x and y variables in JS.


JavaScript auto increment variable HTML Example code

Auto increment variable value by 2

Do comment if you have any doubts and suggestions on this topic.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.