Home JavaScript Centrality CSS Studio Tools Projects Links
Language Reference Code Examples

Javascript Operator Reference

Operators are symbols used to perform an operation. In JavaScript, there are several different kinds of operators, including: arithmetic operators, assignment operators, comparison operators, and logical operators.

Each of these types of operators is described below, with examples.

Arithmetic Operators

Arithmetic operators, as the name implies, are used to perform arithmetic operations upon variables and constants. The table below shows the various arithmetic operators. Click on the Show Me links to try out the operators.


Operator Description Example(s) Results Try It
+ Addition a = 21
b = 6
a + b
27 Show Me
- Subtraction c = 15
d = 3
c - d
12 Show Me
* Multiplication e = 7
f = 6
e * f
42 Show Me
/ Division h = 25
i = 5
h / i
5 Show Me
% Modulus (Remainder) j = 25
k = 7
j % k
4 Show Me
++ Increment by 1 m = 17
m ++
16 Show Me
-- Decrement by 1 n = 25
n --
24 Show Me

Assignment Operators

Assignment operators are used to set the value of a variable. The assignment operators are displayed in the table below.


Operator Description Example(s) Equivalent
= Equals a = 21 a = 21
+= Variable Increment b = 5
b += 6
b = b + 6
-= Variable Decrement c -= 3 c = c - 3
*= Variable Multiplier d *= 3 d = d * 3
/= Variable Divisor e /= 3 e = e / 3
%= Variable Modulus f %= 3 f = f % 3

Comparision Operators

Comparison operators compare two variables or constants and return true or false based on whether or not the values of the two variables or constants pass the comparison test. The various comparison operators are shown in the table below.


Operator Description Example(s) Returns
== Tests for Equality given a = 5
a == 21
false
> Greater Than given b = 4
b > 2
true
< Less Than given c = 8
c < 21
true
>= Greater Than or Equal To given d = 12
d >= 13
false
<= Less Than or Equal To given e = 7
e <= 7
true

Logical Operators

Logical operators are used to combine and test (in the case of && and ||) or invert and test (in the case of !) javascript statements. The three types of logical operators are shown in the table below.


Operator Description Example(s) Returns
&& Logical AND given a = 5 and b = 6
a == 5 && b == 6
true
|| Logical OR given c = 12 and d = 3
c == 12 || b = 6
true
! Logical NOT given e = 10 and f = 6
! (e == f)
true