20.3. Calculations and Operators
JavaScript supports the standard operators for numbers and strings. The following tables outline the basic operators available in JavaScript.
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 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 |
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 returning a value |
String Operators
Operator | Use |
---|---|
+ | Concatenation |
String Tokens
Token | Character |
---|---|
\\ | Backslash |
\' | Single quote |
\" | Double quote |
\b | Backspace |
\f | Form Feed |
\n | Line Feed |
\r | Carriage Return |
\t | Horizontal Tab |
\v | Vertical Tab |
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.