Operators in Javascript
1. Arithmetic
+ Addition
- Subtraction
* Product
/ Division
% Modulus (5%2 = 1)
a = a+b
a + = b
a = a-b
a - = b
a = a*b
a * = b
a = a / b
a / = b
a = a % b
a % = b
2. Relational
== Equals to
!= Not equals to
> Greater then
< Less then
>= Greater then or Equals to
<= Less then or Equals to
3. Logical
---------
And &&
Or ||
Not !
If (a==10 && b==20)
{
.....
.....
}
4. Concatenation
+ Addition (if both are numbers)
Concatenation (if any one is string)
5. Assignment
a = 10 ;
a = b ;
6. Incrementation/ Decrementation
++ incrementation
-- Decrementation
Ex :
a = 10 ;
a++; similar to ( a + = 1) that is a = a + 1 => a=11
a-- ; similar to ( a - = 1) that is a = a - 1 => a=9
Post increment
document.write (a++) ;
Pre increment
document.write (++a) ;
i=5;
j=i++; // post increment => j=5, i=6
k=5;
p=++k; // pre increment => p=6, k=6
Note :
Unary operator takes one Value . ( ! , ++ , -- )
Remaining all operators are Binary Operators ( it takes 2 values )
7. Ternary operator
--------------------
Var = ( condition ) ? true val 1 : false val 2
Example
<html>
<head>
<script>
a = 10;
b = 20;
c = ( a > b ) ? a : b;
document.write( c );
</script>
</head>
<body>
</body>
</html>
1. Arithmetic
+ Addition
- Subtraction
* Product
/ Division
% Modulus (5%2 = 1)
a = a+b
a + = b
a = a-b
a - = b
a = a*b
a * = b
a = a / b
a / = b
a = a % b
a % = b
2. Relational
== Equals to
!= Not equals to
> Greater then
< Less then
>= Greater then or Equals to
<= Less then or Equals to
3. Logical
---------
And &&
Or ||
Not !
If (a==10 && b==20)
{
.....
.....
}
4. Concatenation
+ Addition (if both are numbers)
Concatenation (if any one is string)
5. Assignment
a = 10 ;
a = b ;
6. Incrementation/ Decrementation
++ incrementation
-- Decrementation
Ex :
a = 10 ;
a++; similar to ( a + = 1) that is a = a + 1 => a=11
a-- ; similar to ( a - = 1) that is a = a - 1 => a=9
Post increment
document.write (a++) ;
Pre increment
document.write (++a) ;
i=5;
j=i++; // post increment => j=5, i=6
k=5;
p=++k; // pre increment => p=6, k=6
Note :
Unary operator takes one Value . ( ! , ++ , -- )
Remaining all operators are Binary Operators ( it takes 2 values )
7. Ternary operator
--------------------
Var = ( condition ) ? true val 1 : false val 2
Example
<html>
<head>
<script>
a = 10;
b = 20;
c = ( a > b ) ? a : b;
document.write( c );
</script>
</head>
<body>
</body>
</html>
No comments:
Post a Comment