Quick Links
JavaScript Operator are symbols that are used to perform operations on operands.
Types of JavaScript Operator
- Arithmetic Operators
- Comparison (Relational) Operators
- Bitwise Operators
- Logical Operators
- Assignment Operators
- Special Operators
Arithmetic Operators
Arithmetic operators are used to perform arithmetic operations on the operands.
- + :Addition
- – :Substraction
- * :Multiplication
- / :Divide
- % :Modulus(Remainder)
- — :Decrement. Example: var a=10; a–; Now a = 9
- ++ :Increment. Example: var a=10; a++; Now a = 11
Comparison Operators
The JavaScript comparison operator compares the two operands.
- == :Is equal to. Example: 10==20 = false
- === :Identical (equal and of same type). Example: 10==20 = false
- != :Not equal to. Example: 10!=20 = true
- !== :Not Identical. Example: 20!==20 = false
- > :Greater than. Example: 20>10 = true
- >= :Greater than or equal to. Example: 20>=10 = true
- < :Less than. Example: 20<10 = false
- <= :Less than or equal to. Example: 20<=10 = false
Bitwise Operators
The bitwise operators perform bitwise operations on operands. The bitwise operators are as follows:
- & :Bitwise AND. Example: (10==20 & 20==33) = false
- | :Bitwise OR. Example: (10==20 | 20==33) = false
- ^ :Bitwise XOR. Example: (10==20 ^ 20==33) = false
- ~ :Bitwise NOT. Example: (~10) = -10
- << :Bitwise Left Shift. Example: (10<<2) = 40
- >> :Bitwise Right Shift. Example: (10>>2) = 2
- >>> :Bitwise Right Shift with Zero. Example: (10>>>2) = 2
Logical Operators
The following operators are known as JavaScript logical operators.
- && :Logical AND. Example: (10==20 && 20==33) = false
- || :Logical OR. Example: (10==20 || 20==33) = false
- ! :Logical Not. Example: !(10==20) = true
Assignment Operators
The following operators are known as JavaScript assignment operators.
- = :Assign. Example: 10+10 = 20
- += :Add and assign. Example: var a=10; a+=20; Now a = 30
- -= :Subtract and assign. Example: var a=20; a-=10; Now a = 10
- *= :Multiply and assign. Example: var a=10; a*=20; Now a = 200
- /= :Divide and assign. Example: var a=10; a/=2; Now a = 5
- %= :Modulus and assign. Example: var a=10; a%=2; Now a = 0
Special Operators
The following operators are known as JavaScript special operators.
- (?:) :Conditional Operator returns value based on the condition. It is like if-else.
- , :Comma Operator allows multiple expressions to be evaluated as single statement.
- delete :Delete Operator deletes a property from the object.
- in :In Operator checks if object has the given property
- instanceof :checks if the object is an instance of given type
- new :creates an instance (object)
- typeof :checks the type of object.
- void :it discards the expression’s return value.
- yield:checks what is returned in a generator by the generator’s iterator.
Welcome to JavaScript!
JavaScript in Detail
External JavaScript
Syntax in JavaScript
Comments in JavaScript
Variables in JavaScript
Operators in JavaScript