Javascript Operators
Arithmetic
| Operator | Operation | Notes |
|---|---|---|
+ |
Addition and Concatenation | Concatenation is the combination of strings. "web" + "site" = "website" |
- |
Subtraction | |
* |
Multiplication | |
/ |
Division | |
% |
Modulus (remainder) | d%e; returns the remainder after d is divided by e |
++ |
Increment | a++; is the same as a=a+1; |
-- |
Decrement | a--; is the same as a=a-1; |
Assignment
| Operator | Operation | Notes |
|---|---|---|
= |
Assigns the second value to the first | a = b or "a is assigned the value of b" |
+= |
Addition assigment | a += b; is the same as a = (a+b); |
-= |
Subtraction assigment | a -= b; is the same as a = (a-b); |
*= |
Multiplication assigment | a *= b; is the same as a = (a*b); |
/= |
Division assigment | a /= b; is the same as a = (a/b); |
%= |
Modulus assigment | a %= b; is the same as a = (a%b); |
Logical - result is "true" or "false"
| Operator | Operation | Notes |
|---|---|---|
&& |
Logical AND | Returns "true" if BOTH are true |
|| |
Logical OR | Returns "true" if EITHER is true |
! |
Logical NOT | Toggle - returns "true" if the item is false and "false" if the item is "true". |
Comparative - result is "true" or "false"
| Operator | Operation | Notes |
|---|---|---|
== |
Equality | a = (b == c) a is set to true if b is the same as c, false otherwise |
!= |
Inequality | a = (b != c) a is set to false if b is the same as c, true otherwise |
> |
More than | a = (b > c) a is set to true if b is more than c, false otherwise |
< |
Less than | a = (b < c) a is set to true if b is less than c, false otherwise |
>= |
More than or equal | a = (b >= c) a is set to true if b is more than equal to c, false otherwise |
<= |
Less than or equal | a = (b <= c) a is set to true if b is less than equal to c, false otherwise |
Conditional
| Operator | Operation | Notes |
|---|---|---|
a ? b : c |
if a is true do b if a is false do c |
var is_ie = browser_id(); ("is_ie") ? alert("Welcome, IE user") : alert("Welcome, non IE user"); |
Page Updated
12.08.2009
