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>
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
JavaScript Book
Language Basics
Operators:
- JavaScript Operators
- Increment/Decrement Operators
- Increment/Decrement Operators for String, Boolean, Floating-point and Object
- Unary Plus and Minus
- Bitwise Not operator
- Bitwise AND
- Bitwise OR
- Bitwise XOR
- Left Shift
- Signed Right Shift
- Unsigned Right Shift
- Logical NOT
- Logical AND
- Logical OR
- Multiply
- Divide
- Modulus
- Add
- Subtract
- Relational Operators
- Equal and Not Equal
- Identically Equal and Not Identically Equal
- Conditional Operator
- Assignment Operators
- Comma Operator