Javascript operator
Assignment Operator

Assignment Operator is used to assign value to the variable

like

var name="som kumar";

var salary=15000;

var status=true;

Arithmetic Operators

Arithmetic operator is use to perform arithmetic operation between operands. Some arithmetic operator are +,-,*,/,%

+ is use to add values
- is use to subtract values
* is use to muliply values
/ is use to divide values
% is use to get remainder
Example:-

<script language="javascript" type="text/javascript">
var x=2;
var y=3;
var z=x+y;
document.write(z);
</script>

Output:-
5

Example:-

<script language="javascript" type="text/javascript">
document.write("Javascript is"+"programming language");
</script>
Output:-
Javascript is programming language

Comparison Operators

Comparison operators are used to compare variables and values.

comparison operators with meaning:
< Less then
<= Less then or equal to
> Greater
>= Greater than or equal to
= = Equal to
!= Not equal to
= = = Equal to (with same data type)
!== Not equal to (or don't have the same type)

basically we use comparison operator with if statement like

Example:-
var x=2;
var y=5;
if(x<y)
alert("First value smaller");
else
alert("Second value smaller");

Increment/Decrement Operators

Increment operator(++) is used to increment value means to add 1 to its operand same as decrement operator is subtract 1

Example:-
<script language="javascript">
var x=3;
document.write(++x);
document.write(x++);
document.write(x);
</script>

output:-
4
4
5

Example:-
<script language="javascript">
var x=3;
document.write(--x);
document.write(x--);
document.write(x);
</script>

output:-
2
2
1

Logical Operators

Logical Operator are &&,||,!

&& is use to check with two more condition if all condition true then this return true
|| is use to check with two more condition if any one condition true then this return true.
! when condition is false this return true otherwise true

Example:-
var x=2;
var y=8;
var z=5;
if(x>y && x>z)
document.write("first number greater");
elseif(y>x && y>z)
document.write("second number greater");
else
document.write("third number greater");

output:-
second number greater

?: Operator

?: operator is use to check condition. this is just like if/else statement.

Example:-
var x=8;
(x>5)?alert("x is greater than 5"):alert("x is less tan 5");

output:-
output in alert box x is greater than 5
 

Void Operator

void operator evaluate expression but it does not return a value.

Example:-
var a,b,c,d;
a=void(b=5,c=8,d=56);

document.write('a='+a);

output:-
undefined


Previous
Next