Javascript Operator
What is Operator?
Let's explore the diverse varieties of operators in JavaScript:
Arithmetic Operators:
Arithmetic operators carry out essential mathematical operations consisting of plus, minus, divide and multiply on numeric values.
Addition (+):
let sum = 5 + 3; // sum is 8
Subtraction (-):
let difference = 10 - 4; // difference is 6
Multiplication (*):
let product = 2 * 5; // product is 10
Division (/):
let quotient = 15 / 3; // quotient is 5
Modulus (%):
let remainder = 17 % 5; // remainder is 2
Comparison Operators:
Comparison operators are towards values and go back boolean consequences.
Equal (==):
let isEqual = 5 == '5'; // isEqual is true (loose equality)
Strict Equal (===):
let isStrictEqual = 5 === '5'; // isStrictEqual is false (strict equality)
Not Equal (!=):
let notEqual = 10 != '10'; // notEqual is false (loose inequality)
Strict Not Equal (!==):
let strictNotEqual = 10 !== '10'; // strictNotEqual is true (strict inequality)
Greater Than (>):
let greaterThan = 15 > 10; // greaterThan is true
Less Than (<):
let lessThan = 3 < 8; // lessThan is true
Greater Than or Equal To (>=):
let greaterOrEqual = 20 >= 20; // greaterOrEqual is true
Less Than or Equal To (<=):
let lessOrEqual = 5 <= 2; // lessOrEqual is false
Logical Operators:
Logical operators are used to combine or modify boolean values.
AND (&&):
let andResult = true && false; // andResult is false
OR (||):
let orResult = true || false; // orResult is true
NOT (!):
let notResult = !true; // notResult is false