JavaScript Arithimatic

In JavaScript, arithmetic operators are used to perform mathematical computations on numeric values. Here are the commonly used arithmetic operators:


1. Addition (+):

- Adds two values together.
- Example: `let sum = 5 + 3; // sum = 8`


2. Subtraction (-):

- Subtracts one value from another.
- Example: `let difference = 10 - 4; // difference = 6`


3. Multiplication (*):

- Multiplies two values.
- Example: `let product = 3 * 6; // product = 18`


4. Division (/):

- Divides one value by another.
- Example: `let quotient = 12 / 4; // quotient = 3`


5. Remainder/Modulus (%):

- Returns the remainder of a division operation.
- Example: `let remainder = 15 % 7; // remainder = 1`


6. Exponentiation (**):

- Raises the left operand to the power of the right operand.
- Example: `let result = 2 ** 3; // result = 8`


7. Increment (++) and Decrement (--):

- Increment increases the value of a variable by 1.
- Decrement decreases the value of a variable by 1.
- Example:

javascript
let counter = 5;
counter++; // counter = 6
counter--; // counter = 5

These operators can be used with both literal values and variables. Parentheses can be used to control the order of operations when needed. For example, `(2 + 3) * 4` will give the result of `20`.

It's important to note that JavaScript follows the standard mathematical order of operations (PEMDAS/BODMAS), where multiplication, division, and modulus have higher precedence than addition and subtraction. However, using parentheses can override the default precedence to enforce specific calculations.

Arithmetic operators are fundamental for performing calculations in JavaScript and are widely used in mathematical operations, data manipulation, and complex algorithms.



About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext