You are currently viewing Relational Operators in Javascript With Example

Relational Operators in Javascript With Example

Relational Operators in Javascript

In this article, we will see about relational operators in javascript.

What are Relational operators?

It is also known as Comparison operators. It is one of the types of operators in Javascript. They are used to compare relationships between two values; on the comparison, they yield the result as either true or false.

  • < : Less than
  • > : Greater than
  • <= : Less than or equal to
  • >= : Greater than to equal to
  • == : Equal to
  • != : Not equal to
  • === : Strictly equal to
  • !== : Strictly not equal to

Example code

Less than

document.write(5<8); // true
document.write(10<5); //false

Greater than

document.write(5>8); // false
document.write(10>5); //true

Less than or equal to

document.write(5<=6); // (5<6) or (5==6) - true
document.write(6<=6); // (6<6) or (6==6) - true
document.write(7<=6); // (7<6) or (7==6) - false

Greater than to equal to

document.write(7>=6); // (7<6) or (7==6) - true
document.write(6>=6); // (6<6) or (6==6) - true
document.write(5>=6); // (5<6) or (5==6) - false

Equal to

document.write(7==6); // false
document.write(6==6); // true

Not Equal to

document.write(7!=6); // true
document.write(6!=6); // false

Strictly equal to

document.write(10===7); // false
document.write(7===7); // true

Strictly not equal to

document.write(10!==7); // true
document.write(7!==7); // false

Leave a Reply