Loading Please Wait...
JavaScript Operators are used to perform operations and calculations on numbers, string, variables, etc.
JavaScript has following types of operators:
The numbers or variables used in operations are called operands.
The operation to be performed between numbers or variables is defined by an operator.
Example | Operands | Operator |
---|---|---|
5 + 6 | 5 , 6 | + |
a - b | a , b | - |
a * 6 | a , 6 | * |
Arithmetic Operators are used to perform arithmetic operatiorns:
Operators | Description | Example |
---|---|---|
+ | Addition | a + b |
- | Subtraction | a - b |
* | Multiplication | a * b |
** | Exponentiation | a ** b |
/ | Division | a / b |
% | Modulus (Remainder) | a % b |
++ | Increment | a++ |
-- | Decrement | --a |
Assignment Operators assign values to JavaScript variables.
Operators | Example | Same As |
---|---|---|
= | a = b | a = b |
+= | a += b | a = a + b |
-= | a -= b | a = a - b |
*= | a *= b | a = a * b |
/= | a /= b | a = a / b |
%= | a %= b | a = a % b |
Comparison Operators are used to compare variables and values.
Operators | Description | Example |
---|---|---|
== | equal to (value) | a == b |
=== | equal value and equal type | a === b |
!= | not equal (value) | a != b |
!== | not equal value or not equal type | a !== b |
> | greater than | a > b |
< | less than | a < b |
>= | greater than or equal to | a >= b |
<= | less than or equal to | a <= b |
Logical Operators are used to determine the logic between variables or values.
Operators | Description | Example |
---|---|---|
&& | logical AND | a && b |
|| | logical OR | a || b |
! | logical NOT (Negation) | !a |
Any numeric operand in the operation is converted into a 32 bit number. The result is converted back to a JavaScript number.
Operators | Description | Example |
---|---|---|
& | AND | a & b |
| | OR | a | b |
~ | NOT (Negation) | ~a |
^ | XOR | a ^ b |
<< | left shift | a << b |
>> | right shift | a >> b |
>>> | unsigned right shift | a >>> b |
Operators | Description | Example |
---|---|---|
typeof | Returns the type of a variable | typeof a |
instanceof | Returns true if an object is an instance of an object type | instanceofa |
JavaScript also contains a conditional (ternary) operator that assigns a value to a variable based on some condition.
Syntax
variablename = (condition) ? value1:value2
Example
let voteable = (age < 18) ? "Too young" : "Old enough";
How you feel about this blog:
Share this blog on:
If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com
Contact UsWe are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..
Copyright ©
, Lynxsia IT Solutions, All rights reserved