DEV Community

Mohamed Haarish
Mohamed Haarish

Posted on

operators in javascrip.

Operators are special symbols used in JavaScript to perform calculations and compare values.

In the example, a = 10 and b = 3.

Arithmetic Operators

  1. Addition +

console.log(a + b); // 13
Adds two values.

  1. Subtraction -

console.log(a - b); // 7
Subtracts one value from another.

  1. Multiplication *

console.log(a * b); // 30
Multiplies two values.

  1. Division /

console.log(a / b); // 3.333...
Divides one value by another.

  1. Modulus %

console.log(a % b); // 1
Returns the remainder after division.

  1. Exponentiation **

console.log(a ** b); // 1000

Raises a to the power of b.

Comparison Operators
Comparison operators are used to compare two values.

console.log("9" == 9); // true
console.log("9" === 9); // false
console.log("1" !== 1); // true

• == checks values and can convert the data type.
• === checks both value and data type.
• !== checks that the value or data type is different.

Conclusion

JavaScript operators are important for calculations, comparisons, and decision-making in programs. Arithmetic operators perform mathematical operations, while comparison operators help us compare values.

Top comments (0)