Learn to Code

Searchβ¦

Operators

Operators are a type of construct which represents an action or relationship. We can use them to compare and modify values. You are already familiar with some of the more common operators, such as the ones commonly used in mathematical expressions.

Math Operators

`+`

Addition`-`

Subtraction`*`

Multiplication`/`

Division`%`

Remainder`**`

Exponent

These work largely the same as their math counterparts, and can be used to combine values into new values resulting from the expressions you write.

var sumOfNumbers = 1 + 3;

alert(sumOfNumbers);

Comparison Operators

While the previous operators are used to create and modify values, these ones are used to compare values. The most common ones are:

`==`

Equal to`===`

Identical to`>`

Greater than`<`

Less than`>=`

Greater than or equal to`<=`

Less than or equal to

There is an important distinction between

`==`

and `===`

which is that the "equal to" operator essentially only compares that two values are equivalent, while the "identical to" operator checks that the identity of the values is also the same. What this means is that the "identical to" operator also checks the type of the variable.Because of this, the following occurs:

`"1" == 1; // true`

. This is true because the values are equivalent when not considering the types`"1" === 1; //false`

. This is false, because even though the values are equivalent, they are different types (string vs number) so they are not identicalLast modified 2yr ago

Copy link

On this page

Math Operators

Comparison Operators