Please note, this is a STATIC archive of website webdevelopmenttutorials.com from July 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.

Tutorials

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.

Javascript Operators Tutorial

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.

Arithmetic operators

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

Comparison operators

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

Operator precedence

Expression contained in paranthesis have the highest precedence.

The order of operator precedence after paranthesis is as follows:

  1. Unary operators: ++, --, -, !
  2. Arithmethic operators: *, /, %, +, -
  3. Comparison operators: >, <, >=, <=
  4. Logical operators: &&, ||
  5. Conditional operator: ?:
  6. Assignment operator: =

If the operators have the same level of precedence in an expression, javascript evaluates the operators from left to right.