Learn web design and programming with our free video and text tutorials.
Web Designer? Design and market your own professional website with easy-to-use tools.
In javascript, operators are symbols that are used to manipulate or perform operations on values and expressions. Javascript operators are most commonly used to assign values to variables, perform arithmetic operations, compare values and perform Boolean operations.
Given that a=5, b=10 and c=12, the table below explains the arithmetic operators:
Operator | Description | Example | Result |
---|---|---|---|
+ | addition | a + b | 15 |
- | subtraction | b - a | 5 |
* | multiplication | a * b | 50 |
/ | division | b / a | 2 |
% | modulus | c % a | 2 |
++ | increment | a = a++ | 6 |
-- | decrement | a = a-- | 4 |
Operator | Description | Example | Result |
---|---|---|---|
== | equl to | a == b | false |
!= | not equal to | a != y | true |
< | less than | a < y | true |
> | greater than | a > y | false |
<= | less than or equal to | a <= b | true |
>= | greater than or equal to | a >= b | false |
Expression contained in paranthesis have the highest precedence.
The order of operator precedence after paranthesis is as follows:
If the operators have the same level of precedence in an expression, javascript evaluates the operators from left to right.