No icon

JAVASCRIPT OPERATORS

JAVASCRIPT OPERATORS

JAVASCRIPT OPERATORS

In this topic will discuss about JavaScript Operators 

Types of Operators 
   1. Arithmetic Operators 
   2. Assignment Operators 
   3. String Operators 
   4. Type Operators 
   5. Comparison Operators 
   6. Logical Operators 
   7. Bitwise Operators

JAVASCRIPT OPERATORS WITH EXPLANATION

1. ARITHMETIC OPERATOR 

In Arithmetic operators there are 7 types are present, those all arithmetic operators with Examples Explained below.

 + - / * ++ -- ** 

Lets Discuss Onebyone Clearly 

ADDITION, SUBTRACTION, MULTIPLICATION AND DIVISION

<html> 
      <head>

            SCRIPT 

                    var x=10;
                    var y=20;
                    Document.write (x+y);        OUTPUT : 30
                    Document.write ('BR/');
                     
                    Document.write (x-y);        OUTPUT : -10
                    Document.write ('BR/');
                    
                    Document.write (x/y);        OUTPUT : 0.5
                    Document.write ('BR/');
                    
                    Document.write (x*y);        OUTPUT : 200
  
                          
    
           /SCRIPT
           
       </head>
<body>
</body>
</html>

INCREMENT OPERATION : Arithmetic increment operation is two types 

1. PRE INCREMENT

<html> 
      <head>
    
           SCRIPT
           
           VAR X=10;
           Document.write(++x);


OUTPUT :10;    
           
           /SCRIPT


      </head>

<body>

</body>

</html>
                      
                      
2. POST INCREMENT

Post increment means it will increment the value and prints the updated value in next usage

<html> 
      <head>
    
           SCRIPT
 
Example -1 

           VAR X=10;
           Document.write(x++);  

 OUTPUT :10;

Example -1   

           VAR X=10;
           Document.write(x++);
OUTPUT :10;
           Document.write(x);           
OUTPUT :11;
           
           /SCRIPT


      </head>

<body>

</body>

</html>


DECREMENT OPERATION : Arithmetic decrement operation is two types

1. PRE DECREMENT 


<html> 
      <head>
    
           SCRIPT
           
           VAR X=10;
           Document.write(--x);
           OUTPUT :9;    
           
           /SCRIPT


      </head>

<body>

</body>

</html>

2. POST DECREMENT

<html> 
      <head>
    
           SCRIPT
 
Example -1 
           VAR X=10;
           Document.write(x--);   
OUTPUT :10;

Example -1   
           VAR X=10;
           Document.write(x--);
OUTPUT :10;
           Document.write(x);           
OUTPUT :9;
           
           /SCRIPT


      </head>

<body>

</body>

</html>


EXPONENTIAL OPERATOR

<html> 
      <head>
    
           SCRIPT
  
           VAR X=10;
           VAR Y=X**3;
           Document.write(Y);
           
OUTPUT IS : 1000.
[(y=x**n) In Exponential Operation x value is multiplied with x value  in "n" times and the n value is given after exponetioal operation]
           
           /SCRIPT


      </head>

<body>

</body>

</html>


2.ASSIGNMENT OPERATOR 

SAME AS ARITHMETIC OPERATOR WITH SOME EXTRA ADDTIONAL OPERATORS 

= += -= /= *= **=

Its function is that i will assign the right hand values to left hand variables

EXPLANATION :

<html> 
      <head>
    
           SCRIPT
           
ADDITION

           VAR x=10;
           x+=10;     
[x+=10 It means add 10 value with x and result will srore in X variable onle i.e x=x+10
           Document.write(x);
OUTPUT :20; 
x=x+10 => x+=10 [Short form]

SUBTRACTION

           VAR x=10;
           x-=2;     

OUTPUT :8; 

MULTIPLICATION
   
           VAR x=10;
           x*=2;     

OUTPUT :20; 

DIVISION

           VAR x=10;
           x/=2;     

OUTPUT :5; 

EXPONENTIAL

           VAR x=10;
           x**=2;     

OUTPUT :100; 
            
           /SCRIPT


      </head>

<body>

</body>

</html>


3.STRING OPERATOR 

It is used if you want to add or concatenate two strings 

 +

<html> 
      <head>
    
           SCRIPT
  
           var fname='Abdul';
           var lname='Ahamad';
           Document.write(fname+lname);
OUTPUT : AbdulAhamad.
           Document.write(fname+''+lname); [ To get the space between two strings]
OUTPUT : Abdul Ahamad.

           var x=10;
           var y='10';
           [removed](x+y);

OUTPUT :1010
           
           /SCRIPT


      </head>

<body>

</body>

</html>

4.TYPE OPERATOR

1.Typeof 
 it will give the variables data type 

<html> 
      <head>
            
            SCRIPT   

               var x=10;
               Document.write (typeof x);
               
OUTPUT : NUMBER;
               
            /SCRIPT
            
      </head>
<body>
</body>
</html>
 
2.INSTANCE OF
we will discuss about instance of operator while we discuss about object oriented programming .


5. COMAPARISON

== === > < != !== >= <= ?

=      Assignment [Assignes the righthand side value to lefthand side value]
==     Comparison the values
===    Comapres values along with Compares Datatypes
< >    Condition Checking
!=     If left hand side value and right hand side values are not equal to it give result TRUYE
!==    If left hand side value and right hand side values are not equal and check datatype also in data type also not same it gives the result TRUE
>=     Checks x values greater or euql to y 
<=     Checks x values lessthan or euql to y


TERNARY OPERATOR [?]

SHORT VERSION OF IF AND ELSE CONDITION

EXAMPLE :
<html> 
      <head>
            
            SCRIPT   

               var marks=50;
               var result=(marks>60)?"1st":"Any";
               Document.write (result);
               
OUTPUT : Any

               var age=50;
               var result=(age>=60)?"S. Citizen":"No";
               Document.write (result);
               
OUTPUT : No
               
            /SCRIPT
            
      </head>
<body>
</body>
</html>

6. LOGICAL OPERATOR 

Conditional operators 

&& [AND]
|| [OR]
!  [NOT]

<html> 
      <head>
            
            SCRIPT   

AND OPERATOR
               var X=12;
               var y=12;
               var result=(x>5 && y>8);
               Document.write (result);
OUTPUT : true

OR OPERATOR
               var X=12;
               var y=12;
               var result=(x>5 || y<8>                Document.write (result);
OUTPUT : true

NOT OPERATOR
               var x=true;
               Document.write (!x);
OUTPUT : false
               
            /SCRIPT
            
      </head>
<body>
</body>
</html>


7.BITWISE OPERATOR 

32bits [ 32 16 8 4 2 ]

& | ~ ^ << >>

& AND
| OR
~ NOT
^ EX-OR
<< LEFT> >> RIGHT-SHIFT

These Bitwise operations will performed as per guidelines .

EXAMPLE 

Document.write (~5);
Explanation : (~5) =[-(5+1)];


These all are the types of JAVASCRIPT OPERATORS

 

Comment As:

Comment (0)