Basic Arithmetic Operators
Here’s an example of using these operators to perform arithmetic operations:
let x = 10; let y = 5; let z = x + y; // Addition let w = x - y; // Subtraction let a = x * y; // Multiplication let b = x / y; // Division
% symbol. The modulus operator returns the remainder of a division operation.
Here’s an example of using the modulus operator:
let x = 10; let y = 3; let z = x % y; // Modulus
In this example,
z will be equal to
10 divided by
3 gives a remainder of
Increment and Decrement Operators
1 from a variable.
The increment operator is represented by
++, and the decrement operator is represented by
--. Here’s an example:
let x = 10; x++; // x is now 11 x--; // x is now 10 again
These operators can be used either before or after the variable name, depending on whether you want to perform the operation before or after the variable is used in an expression.
- Increment and decrement operators
- Multiplication and division operators
- Modulus operator
- Addition and subtraction operators