Create a new page called operators.html and put this code inside a script element inside the head element:

var fred=3;
if (fred==3) {
    alert('the same');
} else {

You can try the page if you want but what happens should not be a surprise so read the code first!

The first line assigns a value to the variable called fred.  The equals sign (=) is known as an assignment operator.

In the second line the == is a comparison operator.  It compares what is on both sides and if they are the same it replies true.  In this example fred does equal 3 so the if statement condition is said to be true

Change the number in the first line.  Try the page again.  The condition now returns false.  That means the code in the else runs.


Move the existing JavaScript code into a function called equalToOperator() in a script element inside the head.  Create a paragraph with an event trigger by using this code:

<p onmouseup="isEqualToOperator();">Is 3 equal to 3?</p>

Check that it still works and then change the number back to 3 so it makes sense and test again.

There are other comparison operators.  Create functions and paragraphs to demonstrate each of these trying different numbers and messages: