There are three types of operators that can be used in programs:
Table of Contents |
---|
Mathematical Operators
Mathematical operators work on two numbers and return a number.
...
JavaScript ES5 does not have an operator for exponentiation. Instead, use the Math.pow function. For example, Math.pow(2, 3) returns 8 (2 raised to the power of 3).
Logical Operators
Logical Operators take in two Boolean values and output a another Boolean value.
Operator | Function | Example | Description |
| Logical AND |
| If value in variables |
| Logical OR |
| If value in variables |
| Logical NOT |
| Returns the logical inverse. If A evaluates to |
...
All other values are evaluated as true
.
Comparison Operators
Comparison operators compare two expressions and return true
if the comparison is true, and false
otherwise.
Operator | Function | Example | Description |
| Less than |
| If |
| Greater than |
| If |
| Less than or equal to |
| If |
| Greater than or equal to |
| If |
| Equal to |
| If |
| Instance of |
| If |
| Is not equal to |
| If |
| In |
| If there is an instance of |
Assignment Operators
Operator | Function | Example | Description |
| Assignment |
| Stores the value in variable |
| Addition assignment |
| Stores the value |
| Subtraction assignment |
| Stores the value |
| Increment Operator |
| Adds 1 to the value of |
| Decrement Operator |
| Subtracts 1 from the value of |
...
In this case, the value of A
and B
will be set to the value of C
. In other words, the value on the rightmost side of the operator will be used to set the value of the variables on the left. The example mentioned above will be processed internally in the program as shown below:
B
←C
A
←B
Bitwise Operators
A bitwise operator acts on the bit representation of a variable.
...
Operator | Function | Example | Description |
| Bitwise invert |
| Each bit of |
| Remainder |
| Indicates the remainder from the division of |
| Bitwise AND |
| Bitwise logical AND calculation of |
| Bitwise OR |
| Bitwise logical OR calculation of |
| Bitwise XOR |
| Bitwise logical XOR calculation of |
| Bitwise Shift Left |
| Shifts the bits of |
| Bitwise Shift Right (Signed) |
| Shifts the bits of |
| Bitwise Shift Right (Zero Filling) |
| Shifts the bits of |
Special Operators
The following operators do not fit neatly into the above categories.
Operator | Function | Example | Description | ||||
| Check Type |
| Returns a string indicating the type of the specified variable or expression. Possible return values include “string”, “number”, “boolean”, “object”, “function”, “null”, and “undefined”. | ||||
| Void |
| Evaluates the specified expression but uses For example:
This will execute the function | ||||
| New Instance |
| Used to get a new instance of a user-defined object or one of the built-in object types like In the example below, we define a class
|