C.2. Operators
JavaScript Arithmetic Operators
Operator | Use |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Modulus |
++ | Increment |
-- | Decrement |
JavaScript Assignment Operators
Operator | Use |
---|---|
= | Assignment |
+= | Increment assignment |
-= | Decrement assignment |
*= | Multiplication assignment |
/= | Division assignment |
%= | Modulus assignment |
JavaScript Comparison Operators
Operator | Use |
---|---|
== | Is equal to |
=== | Exactly equal to, in value and type |
!= | Is not equal to |
!== | Is not exactly equal to |
> | Is greater than |
< | Is less than |
>= | Is greater than or equal to |
<= | Is less than or equal to |
JavaScript Logical Operators
Operator | Use |
---|---|
&& | And |
|| | Or |
! | Not |
JavaScript Bitwise Operators
Operator | Use |
---|---|
& | And |
| | Or |
^ | Xor |
~ | Not |
<< | Left shift |
>> | Right shift |
>>> | Zero fill right shift |
JavaScript Miscellaneous Operators
Operator | Use |
---|---|
. | Object/property/method separator |
? | Condition operator |
, | Specify multiple expressions in place of one expression. For example, you can use this operator to specify two variables to initialize at the beginning of a for loop:
for (x=0, y=0; x<=20; x++) { // loop code } |
delete | Delete specified object |
new | Create new object |
this | Reference current object |
typeof | Type of object (number, string, and so on) |
void | Evaluate expression without return value |
String Operators
Operator | Use |
---|---|
+ | Concatenation |
Escape Characters
Characters | Description |
---|---|
\' | Single quote |
\" | Double quote |
\\ | Backslash |
\b | Backspace |
\f | Form feed |
\n | Newline |
\r | Carriage return |
\t | Tab |
The backslash can also be used to escape any character simply by prefixing the character with a backslash.
Get Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.