Javascript compare with inequality operator

 Javascript compare with inequality operator

In Javascript we use the inequality operator to check if a particular condition passes or fails.

It is exactly opposite of the equality operator we've covered. If equality operator returns true, the inequality operator would return false.

Let's take a look at an example to understand this. Here, we are checking if the numbers are equal or not. In the first instance five is not equal to six. Thus the result is true. In the second insance, both the numbers are equal. Thus returns false.

<!DOCTYPE html>

<button onclick="inequality(5,6)">Check if 5 = 6</button>
<button onclick="inequality(5,5)">Check if 5 = 5</button>
<p id="result"></p>

    var x = document.getElementById("result");
function inequality(num1num2) {
    if(num1 != num2){
        x.innerHTML = true;
        x.innerHTML = false;


Post a Comment