Operators are capable of manipulating a certain value or operand. Operators are used to perform specific mathematical and logical manipulation on operand.
In Javascript operators are used for compare values, perform arithmetic operations.
Arithmetic operators.
Addition
The + operator produced the sum of numeric operands or string concatenation.
let a = 93 + 44;
console.log(a);
Note: '+' operator can also be used to add strings.
let add = "hey" + "how's" + "life";
Subtraction.
Operator perform subtraction on two operands.
let a = 45;
let b = 20;
console.log(a - b);
Multiplication.
Operator (*) produces the product of the operand.
let x = 3;
let y = 3;
console.log(x * y) ;
Division.
( / ) operator produces the quotient of its operands where the left operand is the dividend and right operand is divisor.
console.log(12 / 2);
Modulas.
It gives remainder of an integer dovision.
Ex- Checking if a number is even is equivalent to checking if n%2===0.
function isEven (n) {
return n%2 ===0;
}
Incremment.
Operator increases an integer value by one.
let x = 3;
let y = x++;
console.log(y);
Assingment opreators.
Assignment operator
It assign right operand value to left operand or it used to assign value to a variable.
let x = 2;
Addition assignment
Sums up left and right operand value and then assign the result to the left operand.
let a = 2;
let b = 'hello';
console.log(a += 3);
...........................
Comparison operators.
Equal to ( == )
The equality operators checks whether its two operands are equal, return a boolean result if equal the condition is true otherwise false.
let a = 2;
let b = 4;
console.log(a == b);
Strict equal to ( === )
Compares equality of two operands with data type. If equal then condition is true otherwise false.
console.log( 'hello' === 'hello' );