Comparison operators are used to compare the equality or difference between variables or values.
We will go through a few of them to demonstrate how they work.
var x = 6;
document.getElementById("demo").innerHTML = (x == 20);
In this test script we have created a variable and assigned it a value of 6.
We will use the
getElementbyID method to output a true or false result, when using different comparison operators to compare our variable value with another value.
Let's start with our equal to (==) operator. Let's test to see if our variable value is equal to 20. We know that this is not the case, so our script should output the word "false".
We can use the "not equal (!=)" operator to see if our variable is not equal to 10. In this case our output should be true, since 6 is not equal to 10.
You can test out the remaining comparison operators and see what the outcome produces.