HTML
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link name="favicon" type="image/x-icon" href="https://skillzam.com/uploads/system/e353194f3b7cd1b75d69c3ab88041985.png" rel="shortcut icon" />
<title>Comparison operators</title>
</head>
<body>
<!--
Comparison and Logical operators are used to test for true or false
Comparison operators can be used in conditional statements to compare values and take action depending on the result
Operator Description
== equal to
=== equal value and equal type
!= not equal
!== not equal value or not equal type
> greater than
< less than
>= greater than or equal to
<= less than or equal to
-->
<h1>Demo: Comparison operators</h1>
<div>
<h2>The output from the "if conditions using Comparison Operators": </h2>
<p id="para1"></p>
<p id="para2"></p>
<p id="para3"></p>
<p id="para4"></p>
<p id="para5"></p>
<p id="para6"></p>
</div>
<!-- JavaScript code Starts here -->
<script>
/************************************************/
// JavaScript Comparison Operators
// In the below examples, if conditions using Comparison Operators are true
//
let a = 13;
let b = 24;
let c = 35;
let d = '13'; // 'd' is string datatype
let e = 13;
let setFlag = false;
if ( a == d ) { // 13 == '13' is true
document.getElementById('para1').innerHTML =
"'a' and 'd' are equal"
}
if ( a === e) { // 13 === 13 is true
document.getElementById('para2').innerHTML =
"'b' and 'e' are STRICT equal"
}
if ( c != e ) { // 35 != 13 is true
document.getElementById('para3').innerHTML =
"'c' and 'e' are NOT equal"
}
if ( c !== d ) { // 35 !== '13' is true
document.getElementById('para4').innerHTML =
"'c' and 'd' are STRICT not equal"
}
if ( b > a ) { // 24 > 13 is true
document.getElementById('para5').innerHTML =
"'b' is greater than 'a'"
}
if ( a >= e ) { // 13 >= 13 is true
document.getElementById('para6').innerHTML =
"'a' is greater than or equal to 'e'"
}
</script>
<!-- JavaScript code Ends here -->
</body>
</html>