3 Example(s) of JavaScript Comparison operators


Description :

Comparison Operator allow you to compare two values and return true or false based on statement. In this example (2 == 12) which is not equal, So it will return false See the code snippet:


JavaScript Comparison operators Example - 1
<!DOCTYPE html>
<html>
 <head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
  <body>
<p id="sample"></p>
<script>
document.getElementById("sample").innerHTML = 2 == 12;
</script>
      </body>
</html>

Output

Description :

Comparing two values with greater than operator (10 > 12 ) which will return false. See the code snippet:


JavaScript Comparison operators Example - 2
<!DOCTYPE html>
<html>
 <head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
  <body>
<p id="sample"></p>
<script>
document.getElementById("sample").innerHTML = 10 > 12;
</script>
      </body>
</html>

Output

Description :

Comparison Operator val!= 9 will return true because value assigned is 8.


JavaScript Comparison operators Example - 3
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
<body>
<p id="sample"></p>
<script>
var val= 8;
document.getElementById("sample").innerHTML = (val!= 9);
</script>
</body>
</html>

Output