"JavaScript operators are used to assign value,compare value,perform arithmatic operation and more."
Example- sum = a + b;
where sum , a,b are(operend) and + =(operator) .....operator and operend called Expression.
Example:-1
var a =10;
var b =20;
var sum = a+b;
document.write(sum);
Example:-2
var a =10;
var b =30;
var sum = a+30;
document.write(sum);
Example:-3
var a =Ganesh;
var b =Singh;
document.write(a + b);
Example:-1
var number =10;
number = number +5;
document.write(number);
Example:-2
var number =20;
number += 5;
document.write(number);
Example:-3
var number =20;
number /= 5;
document.write(number);
Conditional Statement are used to perform different action based on different condition. These are mostly two type.
If - Statement :-If Statement execute some code only if ispecified condition is True.Example :-
var marks =95;
if (marks ==95)
{
document.write("Yes your marks is correct");
}
else
{
document.write("The value is incorrect")
}
Example :-1
id="demo"
var day;
switch (new Date().getDay()) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
}
document.getElementById("demo").innerHTML ="Today is" + day;
Example:-1
var a =2;
var b="2";
if (a == b)
{
document.write("Thes Vaue is eqaul");
}
else
{
document.write("The value are not equal");
}
Note:- The is == value only comapre the value of variable.Because the a=1 is number(no code ) and the b="1" are string but the output is not equal.
Example:-2
var a =2;
var b="2";
if (a === b)
{
document.write("Thes Vaue is eqaul");
}
else
{
document.write("The value are not equal");
}
Note:- The is === value only comapre the value and data type of variable.Because the a=1 is number(no code ) and the b="1" are string but the output is same.
Example:-3
var a =5;
var b="5";
if (a != b)
{
document.write(" Both are eqaul");
}
else
{
document.write("Both are not equal");
}
Note:- The is != value only comapre the value of variable.Because the a=1 is number(no code ) and the b="1" are string but the output is same. but the !== are compare the value and data type of a variable. and output are both are equal
This site design & Develop by Ganesh singh aswal