JS Comparison Operators


Comparison Operators

Ø  Comparison operators are used to determine equality or difference between variables or values in logical statements. Let us some of the most widely used JavaScript Comparison Operators in detail.

Equal operator (==): used to check whether the two given operands are equal or not.

Syntax: x==y

let x =10;

let y=10;

//Equal to the operator:

console.log(x==y); //true

 

 Not Equal operator (!=)

Ø  It checks whether two operands are not equal and return a Boolean value. If two operands being evaluated are not equal, then this gives the value true.

Ø  This operator tries to compare values impartial of whether they are of different types.

Syntax: X != Y

let x =10;

let y=10;

//Equal to the operator:

console.log(x!=y); //false

 

Strict equality operator(===)

Ø  It can be used to compare the equality of two operands with type.

Ø  If both operand and type are equal then the condition is true otherwise false.

Syntax: X === Y

let x =10;

let y="10";

let z = 10;

//=== operator

console.log(x===y); //True

console.log(x===z); //False

 

 Strict inequality operator (!==)

Ø  It checks not equals and not type equals which means the operand and type don’t match; if any of the two conditions are also not true, this evaluates true.

Syntax: X !== Y

let x =10;

let y="10";

let z = 10;

// !== operator

console.log(x!==y); //True

console.log(x!==z); //False

 

Greater than(>)

Ø  It checks the left-side operand and the right-side operand; when the life-side operand is greater than the right-side operand the condition is true otherwise false.

Syntax: X > Y

let x =10;

let y=9;

let z= 11

//greater than the operator

console.log(x>y); //True

console.log(x>z); //False

 

Greater than or Equal to Operator(>=)

Ø  It checks the left-side operand and the right-side operand; when the life-side operand is greater than or equal to the right-side operand the condition is true otherwise false.

Syntax: X > Y

let x =10;

let y=9;

let z= 11

//greater than or equal operator

console.log(x>=y); //True

console.log(x>=z); //False

 

Less than(>)

Ø  It checks the left-side operand and the right-side operand; when the life-side operand is less than the right-side operand the condition is true otherwise false.

Syntax: X < Y

let x =10;

let y=9;

let z= 11

//less than the operator

console.log(x<y); //False

console.log(x<z); //True

 

Less than or Equal to Operator (<=)

Ø  It checks the left-side operand and the right-side operand; when the life-side operand is less than or equal to the right-side operand the condition is true otherwise false.

Syntax: X <= Y

let x =10;

let y=9;

let z= 11

//less than or equal operator

console.log(x<=y); //False

console.log(x<=z); //True

 

 


Leave a comment
No Cmomments yet