Increment/Decrement Operators

The increment operator is ++. The decrement operator is --. The increment and decrement operators have two versions: prefix and postfix.

The prefix operators are placed before the variable. The postfix operators are placed after the variable. The increment operator adds 1 to a numeric value and decrement operatos subtracts 1 from a numeric value:

 
<!DOCTYPE html>
<html>
<head>
    <title>Operator Example</title>
    <script type="text/javascript">

        var num = 4; 
        document.writeln(num); //4 
        ++num; 
        document.writeln(num); //5 
        --num; 
        document.writeln(num); //4
        
    </script>

</head>
<body>
  
</body>
</html>
  
Click to view the demo

The difference between postfix and prefix: the increment or decrement doesn't occur until the containing statement has been evaluated.

Home 
  JavaScript Book 
    Language Basics  

Operators:
  1. JavaScript Operators
  2. Increment/Decrement Operators
  3. Increment/Decrement Operators for String, Boolean, Floating-point and Object
  4. Unary Plus and Minus
  5. Bitwise Not operator
  6. Bitwise AND
  7. Bitwise OR
  8. Bitwise XOR
  9. Left Shift
  10. Signed Right Shift
  11. Unsigned Right Shift
  12. Logical NOT
  13. Logical AND
  14. Logical OR
  15. Multiply
  16. Divide
  17. Modulus
  18. Add
  19. Subtract
  20. Relational Operators
  21. Equal and Not Equal
  22. Identically Equal and Not Identically Equal
  23. Conditional Operator
  24. Assignment Operators
  25. Comma Operator