The arithmetic operators perform addition, subtraction, multiplication, division, exponentiation, and modulus operations.
Examples:
let x = 10;
let y = 4;
console.log(x + y);
//output:14
console.log(x - y);
// output:6
console.log(x * y);
// output:40
console.log(x / y);
// output:2.5
console.log(x % y);
// output:2
console.log(x ** y);
// output:10000
console.log(++x)
//output:11
console.log(--x)
//output:9
An assignment operator assigns a value to its left operand based on the value of its right operand.
let x = 3;
A comparison operator compares its operands and returns a logical value based on whether the comparison is true. The operands can be numerical, string, logical, or object values.
1. Relational operator
2. Equality operator
let x = 1;
//Relational
console.log(x > 0) //output:true
console.log(x >= 1) //output:true
console.log(x < 1) //output:false
console.log(x <= 1) //output:true
//Equality
console.log(x === 1) //output:true
console.log(x !== 1) //output:false
1. Strict equality ( === )
The both value we have on the sides of this operator have the same type and same value
console.log( 1 === 1) //output: true
console.log( '1' === 1) //output: false
2. Lose equality ( == )
he both value we have on the sides of this operator have the same value it won’t check type
console.log( 1 == 1) //output:true
console.log( '1' == 1) //output:true
The conditional operator is the only JavaScript operator that takes three operands: a condition followed by a question mark ( ? ), then an expression to execute if the condition is truthy followed by a colon ( : ), and finally the expression to execute if the condition is falsy.
condition ? runs if true : runs if false
var age = 20;
age >= 18 ? console.log("adult") : console.log("minor"); // Prints: adult
There are three main logical operators.
If both conditions are true then it returns true else false.
var x = 6;
var y = 3;
console.log(x < 10 && y < 1);
// Prints: false
If any one condition is true then it returns true
var x = 6;
var y = 3;
console.log(x < 10 || y < 1);
// Prints: true
If a condition is true, then the NOT operator will make it false.
var x = 6;
var y = 3;
// with out !
console.log(x == y); // Prints
: false
// with !
console.log(!(x == y)); // Prints: true