Math operator part 5

Increment & Decrement



Increment ++
The increment operator increments the numeric value of its operand by one. If placed before the operand, it returns the incremented value. If placed after the operand, it returns the original value and then increments the operand.
Decrement --
The decrement operator decrements the numeric value of its operand by one. If placed before the operand, it returns the decremented value. If placed after the operand, it returns the original value and then decrements the operand. 

Some examples:
As in school mathematics, you can change the order of the arithmetic operations by using parentheses.
Example: var x = (100 + 50) * 3;

Increment and decrement are used for:

Adding or subtracting 1 from a number
To change the sign of the number to "+" or "-"
To get the remainder of the division of two numbers

Comments

Popular posts from this blog

Introducing object part 3

Comparison Operators part 2

Module 2