Operators are used to perform Operations. Now, we get a question, what is Operation. So, here are few example of Operations
So, if you want to perform all these operation, you will need operators for that, and the Numbers or Variables, on which, you will perform, these operations, are called Operands. So, we have 3 terms with us.
There are some predefined symbols for Operators that are being used, and we will discuss about those symbols in this session. Now, because Operotors use symbols, So If we want to define Oerators, then we can define in this way
Operators are Symbol, which are used to perform some operation on the operands.
We are going to discuss different types of operators in this session. We can categorize it in 2 Categories
Arithmetic Operators are used to perform arithmetic operation on operands.
Let’s say we have 2 variables a and b, and we want to perform arithmetic operations on them.
Let’s say that the value of a and b is
let a = 10;
let b = 4;
Operators | Operation | Number of Operand | Syntax | Type |
+ | Addition (Add 2 Numbers) | 2 | a+b | Binary |
– | Subtraction (Subtract 2 Numbers) | 2 | a-b | Binary |
* | Multiplication (Multily 2 Numbers) | 2 | a*b | Binary |
/ | Division (Divide 2 Numbers) | 2 | a/b | Binary |
% | Modulus (Remainder) | 2 | a/b | Binary |
++ | Increment (Increase value by 1) | 1 | a++ | Unary |
— | Decrement (Decrease value by 1) | 1 | a++ | Unary |
Assignment Operators are used to perform assigment operations on the operands. We need atleast 1 Variable for peforming Assignment Operations. Let’s say we have 2 Variables a and b, and the values that they hold is.
let a = 10;
let b = 4;
Operators | Syntax | Operation | Number of Operand | Type |
= | a=b | Assigns value of left variable (b) to right variable(a) | 2 | Binary |
+= | a+=b | a=a+b (Add a and b and assign the result to a) | 2 | Binary |
-= | a-=b | a=a-b (Subtract b from a and assign the result to a) | 2 | Binary |
*= | a*=b | a=a*b (Multiply a and b and assign the result to a) | 2 | Binary |
/= | a/=b | a=a/b (Divide b from a and assign the result to a) | 2 | Binary |
%= | a%=b | a=a%b (Remainder of a/b is assigned to a) | 2 | Binary |
Comparison Operators compares 2 values and then returns either a true value or a false value. Comparison Operators return boolean values.
let’s say we have a variable a with a value of 7
let a = 7;
Operator | Syntax | Operation | Result | Type |
== | a==7 | Compares a with 7 for equal value | true | Binary |
a==”7″ | Compares a with “7” for equal value | true | Binary | |
a==8 | Compares a with 8 for equal value | false | Binary | |
=== | a===7 | Compares a with 7 for equal value and equal type | true | Binary |
a===”7″ | Compares a with “7” for equal value and equal type | false | Binary | |
a===8 | Compares a with 8 for equal value and equal type | false | Binary | |
!= | a!=7 | Compares a with 7 for not equal value | false | Binary |
a!=”7″ | Compares a with “7” for not equal value | false | Binary | |
a!=8 | Compares a with 8 for not equal value | true | Binary | |
!== | a!==7 | Compares a with 7 for not equal value and equal type | false | Binary |
a!==”7″ | Compares a with “7” for not equal value and equal type | true | Binary | |
a!==8 | Compares a with 8 for not equal value and equal type | true | Binary | |
> | a>7 | Compare if a is greater than 7 | false | Binary |
< | a<7 | Compare if a is less than 7 | false | Binary |
>= | a>= | Compare if a is greater than or equal to 7 | true | Binary |
<= | a<= | Compare if a is less than or equal to 7 | true | Binary |
Logical Operators are the Operators that performs Logical Operation. Meaning of Logical Operation is Performing Operation on boolean values and returning a boolean value.
Operator | Description | Syntax | Result | Type |
&& | Logical AND | (true && true) | true | Binary |
(true && false) | false | Binary | ||
(false && false) | false | Binary | ||
|| | Logical OR | (true || true) | true | Binary |
(true || false) | true | Binary | ||
(false || false) | false | Binary | ||
! | Logical NOT | !true | false | Unary |
!false | true | Unary |
We have covered below topics in this session
Why we can not over ride a Constructor This is a very important question, that,…
What is Arrow Function In the last session, We had discussed about Anonymous Function. Anonymous…
What is Anonymous Function Anonymous Function is a type of function which has no name…
What is Map, Reduce and Filter Map Filter and Reduce are higher order methods for…
9 different ways of declaring or defining a function in Javascript In, one of our…
Loops with Arrays in Javascript In our last session, we had seen, What is Array…