Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js
Home  • Programming • JavaScript

জাভাস্ক্রিপ্ট : অপারেটর

learning javascript

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 (+)
  1. <script>
  2. var x=3;
  3. var y= 6;
  4. var z= x + y; // Here plus ( +) sign is used as a arithmetic operator.
  5. alert( z); // output: 9
  6. </script>
Example ( %)
  1. <script>
  2. var x=13;
  3. var y= 5;
  4. var z= x % y; // Here mod ( %) sign is used as a arithmetic operator. It is used to determine the reminder of this operation.
  5. alert( z); // output: 3
  6. </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 (=)
  1. <script>
  2. var x=3; //Here equal sign (=) is used as assignment operator
  3. alert( x); // output: 3
  4. </script>
Example (+=)
  1. <script>
  2. var x=3; //Here equal sign (=) is used as assignment operator
  3. x+=4; // x=x+4 can be used instead of x+=4 .Here plus equal sign (+=) is work as add and assign
  4.  
  5. alert( x); // output: 7;
  6. </script>
Example (-=)
  1. <script>
  2. var x=10; // Here equal sign (=) is used as assignment operator
  3. x-=4; // x=x-4 can be used instead of x-=4. Here minus equal (-=) is work as substract and assign
  4. alert( x); // output: 6;
  5.  
  6. </script>
Example (*=)
  1. <script>
  2. var x=3; //Here equal sign (=) is used as assignment operator
  3. x*=5; // x=x*5 can be used instead of x*=5 Here minus equal (*=) is work as multiply and assign
  4. alert( x); // output: 15;
  5. </script>
Example
  1. <script>
  2. let x=1;
  3. document.write(x );//1
  4. x=3;
  5. document.write(x );//3
  6. x=x+2;
  7. document.write(x );//5
  8. x-=1;//x=x-1
  9. document.write(x );//4
  10. x*=2;// x=x*2;
  11. document.write(x );//8
  12. x/=4;//x=x/4;
  13. document.write(x );//2
  14. x%=2;//x=x%2;
  15. document.write(x );//0
  16. x++;//x=x+1
  17. document.write(x );//1
  18.  
  19. document.write(x++);//1 | 1st. print 2nd. ++
  20. document.write(x--);//2 | 1st. print 2nd. --
  21. document.write(++x);//2 | 1st. ++ 2nd. print
  22. document.write(x );//2
  23.  
  24. </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 (>)
  1. <script>
  2. var x=3;
  3. var y=2;
  4. var z=x>y; // Here (>) is a comparison operator. (x>y) is called simple Boolean expression
  5. alert( z); // output: true;
  6. </script>
Example (==)
  1. <script>
  2. var x=3;
  3. var y="3";
  4. var z=x==y; // Here (==) is a comparison operator. (x==y) is called simple Boolean expression
  5. alert( z); // output: true;
  6. </script>
Example (===)
  1. <script>
  2. var x=3;
  3. var y="3";
  4. var z=x===y; // Here (===) is a comparison operator. (x===y) is called simple Boolean expression
  5. alert( z); // output: false;
  6. </script>

Logical Operators

Symbol Operations
&& And
|| Or
! Not
Example ( && )
  1. <script>
  2. var a=3;
  3. var b=2;
  4. var c=5;
  5. var d=9;
  6.  
  7. 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.
  8. alert( z); // output: true;
  9. </script>

Bitwise Operators

Symbol Operations
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
~ Bitwise NOT
<< Left-shift
>> Right-shift
>>> Zero extension in right-shift
Example (<<)
  1. <script>
  2. var x=3<<1; //Here Left-shift (<<) is a Bitwise operator
  3. alert( x); // output: 6;
  4. </script>

Other Special Operators

Symbol Operations
:? Ternary Operator
typeof Type Of operator
new New Operator
delete Delete Operator
void Void Operator
Example (:?)
  1. <script>
  2. var x=2;
  3. var z=(x>0)?"Positive Number":"Negative Number"; //Here Left-shift (?: ) is a ternary operator
  4. alert( z); // output: Positive Number;
  5. </script>
TOP

Comments 0


Copyright © 2025. Powered by Intellect Software Ltd