Operators are special symbols used in JavaScript to perform calculations and compare values.
In the example, a = 10 and b = 3.
Arithmetic Operators
- Addition +
console.log(a + b); // 13
Adds two values.
- Subtraction -
console.log(a - b); // 7
Subtracts one value from another.
- Multiplication *
console.log(a * b); // 30
Multiplies two values.
- Division /
console.log(a / b); // 3.333...
Divides one value by another.
- Modulus %
console.log(a % b); // 1
Returns the remainder after division.
- 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)