Arithmetic Operators in JavaScript
Arithmetic operators in JavaScript are like the superheroes of your codeâthey handle all the number-crunching tasks. Whether youâre adding, subtracting, multiplying, or dividing, these operators are the muscle behind mathematical operations in your scripts. Letâs explore the world of JavaScript arithmetic operators and see how they make your code flex its numerical muscles.
List of Operators
1. Addition (+)
The addition operator does what youâd expectâit adds two values together.
let sum = 5 + 3; // Result: 8
2. Subtraction (-)
Subtraction, on the other hand, takes one value away from another.
let difference = 10 - 4; // Result: 6
3. Multiplication (*)
Multiplication is all about creating combinations by repeating values.
let product = 2 * 6; // Result: 12
4. Division (/)
Division is like the fair distributorâit shares one value among others.
let quotient = 15 / 3; // Result: 5
5. Remainder (%)
The remainder operator gives you the leftover value after division.
let remainder = 10 % 3; // Result: 1
6. Increment (++) and Decrement (â)
These operators increase or decrease a value by 1.
let num = 5;
num++; // Result: 6
num--; // Result: 5
Conclusion
Arithmetic operators are the superheroes that make your code handle numeric tasks with ease. Whether itâs simple addition, complex multiplication, or finding the remainder, these operators are your trusty companions in the world of JavaScript.
Happy coding!
With arithmetic operators at your disposal, your code becomes a mathematician, effortlessly solving numeric puzzles.