img

What is an Operator?

Let us take a simple expression 8 + 9 is equal to 19. Here 8 and 9 are
called operands and ‘+’ is called the operator. JavaScript
supports the following types of operators. The Addition Operator
+ adds numbers: The
Assignment Operator
= assigns a value to a
variable.

JavaScript Assignment

The Assignment Operator (=) assigns a
value to a variable:

JavaScript Addition

The Addition Operator (+) adds numbers:

JavaScript Multiplication

The Multiplication Operator (*)
multiplies numbers:

Types of JavaScript Operators

There are different types of JavaScript operators:

  • Arithmetic Operators
  • Assignment Operators
  • Comparison Operators
  • String Operators
  • Logical Operators
  • Bitwise Operators
  • Ternary Operators
  • Type Operators

JavaScript Arithmetic Operators

Arithmetic Operators are used to perform arithmetic on numbers:

 

Operator Description
+ Addition
Subtraction
* Multiplication
** Exponentiation (ES2016</a >)
/ Division
% Modulus (Division Remainder)
++ Increment
Decrement

JavaScript Assignment Operators

Assignment operators assign values to JavaScript variables. The
Addition Assignment Operator (+=) adds a
value to a variable.

Operator Example Same As
= x = y x = y
+= x += y x = x + y
-= x -= y x = x – y
*= x *= y x = x * y
/= x /= y x = x / y
%= x %= y x = x % y
**= x **= y x = x ** y

JavaScript Comparison Operators

Operator Description
== equal to
=== equal value and equal type
!= not equal
!== not equal value or not equal type
> greater than
< less than
>= greater than or equal to
<= less than or equal to
? ternary operator

JavaScript String Comparison

All the comparison operators above can also be used on strings: Note that
strings are compared alphabetically:

JavaScript Logical Operators

Operator Description
&& logical and
|| logical or
! logical not

JavaScript Type Operators

Operator Description
typeof Returns the type of a variable
instanceof Returns true if an object is an instance of an object type

JavaScript Bitwise Operators

Bit operators work on 32 bits numbers. Any numeric operand in the operation is
converted into a 32 bit number. The result is converted back to a JavaScript
number.

Operator Description Example Same as Result Decimal
& AND 5 & 1 0101 & 0001 0001  1
| OR 5 | 1 0101 | 0001 0101  5
~ NOT ~ 5  ~0101 1010  10
^ XOR 5 ^ 1 0101 ^ 0001 0100  4
<< left shift 5 << 1 0101 << 1 1010  10
>> right shift 5 >> 1 0101 >> 1 0010   2
>>> unsigned right shift 5 >>> 1 0101 >>> 1 0010   2

Related Posts