জাভাস্ক্রিপ্ট : অপারেটর
INDEX
1.
Arithmetic Operators
2.
Assignment Operators
3.
Comparison Operators
4.
Logical Operators
5.
Bitwise Operators
6.
Special Operators
Arithmetic Operators
Symbol |
Operations |
+ |
Addition |
- |
Subtraction |
* |
Multiplication |
/ |
Division |
% |
Modulus |
Example (+)
<script>
var x=3;
var y= 6;
var z= x + y; // Here plus ( +) sign is used as a arithmetic operator.
alert( z); // output: 9
</script>
Example ( %)
<script>
var x=13;
var y= 5;
var z= x % y; // Here mod ( %) sign is used as a arithmetic operator. It is used to determine the reminder of this operation.
alert( z); // output: 3
</script>
Assignment Operators
Symbol |
Operations |
= |
Assign |
+= |
Add/Concatenate and assign |
-= |
Subtract and assign |
/= |
Divide and assign |
*= |
Multiply and assign |
%= |
Modulus and assign |
++ |
Increment |
-- |
Decrement |
Example (=)
<script>
var x=3; //Here equal sign (=) is used as assignment operator
alert( x); // output: 3
</script>
Example (+=)
<script>
var x=3; //Here equal sign (=) is used as assignment operator
x+=4; // x=x+4 can be used instead of x+=4 .Here plus equal sign (+=) is work as add and assign
alert( x); // output: 7;
</script>
Example (-=)
<script>
var x=10; // Here equal sign (=) is used as assignment operator
x-=4; // x=x-4 can be used instead of x-=4. Here minus equal (-=) is work as substract and assign
alert( x); // output: 6;
</script>
Example (*=)
<script>
var x=3; //Here equal sign (=) is used as assignment operator
x*=5; // x=x*5 can be used instead of x*=5 Here minus equal (*=) is work as multiply and assign
alert( x); // output: 15;
</script>
Example
<script>
let x=1;
document.write(x );//1
x=3;
document.write(x );//3
x=x+2;
document.write(x );//5
x-=1;//x=x-1
document.write(x );//4
x*=2;// x=x*2;
document.write(x );//8
x/=4;//x=x/4;
document.write(x );//2
x%=2;//x=x%2;
document.write(x );//0
x++;//x=x+1
document.write(x );//1
document.write(x++);//1 | 1st. print 2nd. ++
document.write(x--);//2 | 1st. print 2nd. --
document.write(++x);//2 | 1st. ++ 2nd. print
document.write(x );//2
</script>
Output 135482011222
Comparison Operators
Symbol |
Operations |
> |
Greater Than |
< |
Less Than |
>= |
Greater than and Equal |
<= |
Less than and Equal |
== |
Equal |
=== |
Strictly Equal |
!= |
Not Equal |
!== |
Strictly Not Equal |
Example (>)
<script>
var x=3;
var y=2;
var z=x>y; // Here (>) is a comparison operator. (x>y) is called simple Boolean expression
alert( z); // output: true;
</script>
Example (==)
<script>
var x=3;
var y="3";
var z=x==y; // Here (==) is a comparison operator. (x==y) is called simple Boolean expression
alert( z); // output: true;
</script>
Example (===)
<script>
var x=3;
var y="3";
var z=x===y; // Here (===) is a comparison operator. (x===y) is called simple Boolean expression
alert( z); // output: false;
</script>
Logical Operators
Symbol |
Operations |
&& |
And |
|| |
Or |
! |
Not |
Example ( && )
<script>
var a=3;
var b=2;
var c=5;
var d=9;
var z=(a>b ) && (c<d); // Here && is a logical operator. Keep in mind, more than one simple Boolean express combine with logical operator to make a compound Boolean expression. So (a>b ) && (c<d) is a compound Boolean expression.
alert( z); // output: true;
</script>
Bitwise Operators
Symbol |
Operations |
& |
Bitwise AND |
| |
Bitwise OR |
^ |
Bitwise XOR |
~ |
Bitwise NOT |
<< |
Left-shift |
>> |
Right-shift |
>>> |
Zero extension in right-shift |
Example (<<)
<script>
var x=3<<1; //Here Left-shift (<<) is a Bitwise operator
alert( x); // output: 6;
</script>
Other Special Operators
Symbol |
Operations |
:? |
Ternary Operator |
typeof |
Type Of operator |
new |
New Operator |
delete |
Delete Operator |
void |
Void Operator |
Example (:?)
<script>
var x=2;
var z=(x>0)?"Positive Number":"Negative Number"; //Here Left-shift (?: ) is a ternary operator
alert( z); // output: Positive Number;
</script>
TOP
Comments 0