Exploring the World of Relational Operators in JavaScript


In JavaScript, there are several relational operators that can be used to compare values and determine the relationship between them. When using these operators, the expressions on either side of the operator will be evaluated and compared to determine if the relationship between them is true or false

Sno Operator Usage
1. > greater than
2. < less than
3. >= greater than or equal to
4. <= less than or equal to

Greater than (>): This operator compares two values and returns true if the left-side value is greater than the right-side value and false if it is not.

Less than (<): This operator compares two values and returns true if the left-side value is less than the right-side value and false if it is not.

Greater than or equal to (>=): This operator is used to compare two values and determine if the first value is greater than or equal to the second value. If the first value is greater than or equal to the second value, the operator returns true. If the first value is less than the second value, the operator returns false.

Less than or equal to (<=): This operator is used to compare two values and determine if the first value is less than or equal to the second value. If the first value is less than or equal to the second value, the operator returns true. If the first value is greater than the second value, the operator returns false.

Source Code

HTML Code
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Tutor Joes</title>
</head>
<body>
 
	<script src="js/script.js"></script>
</body>
</html>
To download raw file Click Here

The first console.log statement will output "Greater : false" because the value of a is not greater than the value of b.

The second console.log statement will output "Lesser : true" because the value of a is less than the value of b.

The third console.log statement will output "Greater Than Equal : false" because the value of a is not greater than or equal to the value of b.

The fourth console.log statement will output "Greater Than Equal : true" because the value of a is less than or equal to the value of b.

script.js
//Relational Operators in JavaScript
 
/*
>	greater than
<	less than
>=	greater than or equal to
<=	less than or equal to
*/
 
let a=10;
let b=20;
 
console.log("Greater : ",a>b);
console.log("Lesser  : ",a<b);
console.log("Greater Than Equal  : ",a>=b);
console.log("Greater Than Equal  : ",a<=b);
 
To download raw file Click Here

List of Programs


JS Practical Questions & Answers


JS Practical Project