javascript operator javascript string comparison logical operators examples,insertion of javascript in html..

 

Insertion of javascript in html

“+” operator in javascript :

In javascript ‘+’ operator has two meanings , arithmetic addition and string concentration operator.

Example : var a=15+”hello”

Result:15hello

 

Example : var a=15+7+”hello”

Result:22hello

 

Assignment operators (=):

It is important to know that assignment operators is not ‘equal to’ operator.

Assignment operator is used to assign value of an expression to a variable .this means that value

Of an expression on the right hand side is assigned to the single variable on the left hand side .value of variable may change during the next programming instruction.

Example :

Var p=400;//assign value to the variable p

Var e=457.930;//assign value to the variable e

Var a=a+7;//evaluates expression a+7 and assign value at a

Var str=”hello”;//assigns string value to variable str

Var c=d;//assign value of d to c

 

Expression :

There is a difference between algebraic mathematical equations and computer programming statements . following statements are valid expression in algebraic mathematic , but they are invalid in programming languages.

a+b=10;                   //error

a+b=c+d;                //error

c+d=p;                    //error

10=x;                       //error

 X=10;                     //valid

 

Rational operators :

Rational operators are used to check conditions or comparison of operands result of relational operators  is Boolean value ‘true’or ‘false’. They are used in looping and contro structures .following table shows JavaScript  relational operators .

For result consider the value as : a=10,b=30…

Operators

description

example

result

< 

Less then

a>b

True

> 

Greater then

a<b

False

<=

Less then equal to

a<=b

True

>=

Greater then equal to

a=>b

False

==

Equal to

a==b

False

!=

Not equal to

a!=b

true

 

 

Logical operators :

Logical operators are used to verify more then one condition at a time or to negate the condition .

JavaScript has three logical operators .

Operators

description

example

Result

&&(and)

This operator evaluates to’true’ only when all its operands are ‘true’

Var age=25;

Var salary=50000;

If(age>55&&salary>25000)

First condition evaluates to false and second condition evaluates to true ,so that whole expression returns Boolean value as false.

//(or)

This operator evaluates to’true’ when any one of the operand is ‘true’

Var number=-1;

If(number<0//number>100)

First condition evaluates to true  and second condition evaluates to false ,sothat whole expression returns Boolean value true.

!(not)

This  unary operator is used to invert the Boolean expression.

Var z=0;

If(!(z==0))

Expression returns Boolean value as false.

 

Increment(++) and decrement(--)operators :

Increment (++) operator in JavaScript is used to increment value of variables by one

And decrement operator in JavaScript is used to decrement value of variable by one.

They can be used in two ways :

++x

Pre- Increment

Value  of  variable x is incremented before it is used in expression

X++

Post- Increment

Value  of  variable x is incremented after it is used in expression

--x

Pre- decrement

Value  of  variable x is decremented before it is used in expression

x--

Post- decrement

Value  of  variable x is decremented  after it is used in expression

 

Example :

Var a=100;

B=++a;

Output : b=101 and a=101

 

 

 

Var a=100;

B=a++;

Output : b=101 and a=101

 









Comments