The JavaScript multiplication operator ( * ) is used to multiply numbers.

<script>

var a = 4;

var b = 3;

var c = a * b;

document.write(c);

</script>

JavaScript division operator

The JavaScript division operator ( / ) is used to divide numbers.

<script>

var a = 8;

var b = 4;

var c = a / b;

document.write(c);

</script>

JavaScript increment operator

The JavaScript increment operator ( ++ ) is used to increase a number by 1.

Example 1

<script>

var i = 0;

i++;

document.write(i);

</script>

Example 2

<script>

for (var i = 0; i < 5; i++)

{

document.write(i + "<br />");

}

</script>

JavaScript decrement operator

The JavaScript decrement operator ( -- ) is used to decrease a number by 1.

Example 1

<script>

var i = 1;

i--;

document.write(i);

</script>

Example 2

<script>

for (var i = 10; i > 0; i--)

{

document.write(i + "<br />");

}

</script>

JavaScript modulus operator

The JavaScript modulus operator ( % ) is used to calculate the remainder of two values if they were divided.

Modulus produces the remainder value only. It is very useful for seeing if values are divisible by a specified number, check Example 2 below to see it in action that way.

Example 1

<script>

var a = 10;

var b = 3;

var c = a % b;

document.write(c);

</script>

We get the value of "1" as the modulus when 10 is evaluated against 3 because the remainder of dividing those numbers would be "1".

Evaluating 10 against 3 gives us an answer of "3 with remainder of 1".

If you have "10" divided by "5" you get a modulus of "0" since there would be no remainder, 5 goes into 10 twice with no remainder left over so we would get modulus of "0".

Example 2

<script>

for (var i = 1; i <= 20; i++)

{

if (i % 2 == 0)

{ // if value is divisible by the number 2 make it red

document.write("<span style='color:red;'>" + i + "</span><br />");

}

else

{

document.write(i + "<br />");

}

}

</script>

JavaScript equal operator

The JavaScript equal comparison operator ( == ) is used to compare whether the operand on the left is equal to the operand on the right.

The expression created will then return a value of either "true" or "false" to you.

left_operand == right_operand

<script>

var a = 4;

var b = 3;

document.write(a == b);

</script>

You will see it in use most commonly within if...else condition statements.

<script>

var a = 4;

var b = 3;

if (a == b)

{

document.write("YES THAT IS TRUE");

}

else

{

document.write("NO THAT IS FALSE");

}

</script>

JavaScript strict equal operator

The JavaScript strict equal comparison operator ( === ) is similar to the normal equal operator, except that it evaluates the object types also.

If the values are the same but the object types are not the same, this will return false whereas the normal equal operator will return true.

left_operand === right_operand

<script>

var v1 = "5";

var v2 = 5;

if (v1 === v2)

{

document.write("TRUE");

}

else

{

document.write("FALSE");

}

</script>

Now run the same exact code using the normal equal operator.

You will notice that it does not take object type into consideration at all, and will return a value of true even though the left operand is a string object and the right operand is a number object.

<script>

var v1 = "5";

var v2 = 5;

if (v1 == v2)

{

document.write("TRUE");

}

else

{

document.write("FALSE");

}

</script>

JavaScript not equal operator

The JavaScript not equal comparison operator ( != ) is used to check if the operand on the left is not equal to the operand on the right.

The expression created will then return a value of either "true" or "false".left_operand != right_operand

<script>

var v1 = 30;

var v2 = 50;

document.write(v1 != v2);

</script>

JavaScript strict not equal operator

The JavaScript strict not equal comparison operator ( !== ) is used to check if the operand on the left is not equal to the operand on the right, as well as evaluating their object types in the comparison.

The expression created will then return a value of either "true" or "false" to you.

left_operand !== right_operand

<script>

var v1 = "50";

var v2 = 50;

document.write(v1 !== v2);

</script>

"50" does not strictly equal 50 because the first is a string object and the second is a number object.

Even though the values match, the object types do not.

Now run the same exact code using the normal "not equal" operator to see how it does not take object type into consideration in the comparison.

<script>

var v1 = "50";

var v2 = 50;

document.write(v1 != v2);

</script>

JavaScript less than operator

The JavaScript less than comparison operator ( < ) is used to see if the operand on the left is less than the operand on the right.

The expression created will then return a value of either "true" or "false" to you.

left_operand < right_operand

<script>

var v1 = 4;

var v2 = 7;

document.write(v1 < v2);

</script>

or

<script>

var v1 = "abc";

var v2 = "def";

document.write(v1 < v2);

</script>

That will work on strings as well.

JavaScript greater than operator

The JavaScript greater than comparison operator ( > ) is used to see if the operand on the left is greater than the operand on the right.

The expression created will then return a value of either "true" or "false" to you.

left_operand > right_operand

<script>

var v1 = 4;

var v2 = 7;

document.write(v1 > v2);

</script>

or

<script>

var v1 = "abc";

var v2 = "def";

document.write(v1 > v2);

</script>

Will work on strings as well.

JavaScript less than or equal operator

The JavaScript less than or equal to comparison operator ( <= ) is used to evaluate if the operand on the left is less than or equal to the operand on the right.

The expression created will then return a value of either "true" or "false" to you.

left_operand <= right_operand

<script>

var v1 = 5;

var v2 = 5;

document.write(v1 <= v2);

</script>

or

<script>

var v3 = "c";

var v4 = "d";

document.write(v3 <= v4);

</script>

Will work on strings as well.

JavaScript greater than or equal operator

The JavaScript greater than or equal to comparison operator ( >= ) is used to evaluate if the operand on the left is greater than or equal to the operand on the right.

The expression created will then return a value of either "true" or "false" to you.

left_operand >= right_operand

<script>

var v1 = 100;

var v2 = 50;

document.write(v1 >= v2);

</script>

or

<script>

var v3 = "ghi";

var v4 = "def";

document.write(v3 >= v4);

</script>

Will work on strings as well.

JavaScript ternary operator

The JavaScript ternary operator ( ? ) is sort of like a conditional statement.

A ternary operation is one that requires three parameters. It will return the value on the left of the colon ( : ) if the expression is true, and return the value on the right of the colon if the expression is false.

(expression) ? "output for true" : "output for false"

<script>

var a = 5;

var b = 3;

var result = (a > b) ? "that is true" : "that is false";

document.write(result);

</script>

Here is a more advanced example that will show you how to fire off functions in place of returning simple strings.