JavaScript is a Scripting Language.A scripting language is a lightweight programming language.
->It is a client side scripting language.
->javascript is a object based scripting langauge.
->Java script supported
data type(DT), variable, if else ,else if, for, while,do while,switch,operation .function, array,object
->Java script is a loosely typed program(did not take any data type like int,bool,char)
->var is used to over come this
Note: class .inheritance,polymorphisim...etc not supported.
Where you write java script in html page?
Ans:
<html>
<head>
<script language="JavaScript" type="text/JavaScript">
-----
------
------
------
</script>
</head>
</html>
write a program add two number using java script?
ans:
<html>
<head>
<script language="JavaScript" type="text/JavaScript">
var v4=10; //global variable
Function fnadd(v1,v2)
{
var v3=v1+v2;
return v3;
}
Function fnsub(v5,v6)
var v7=v5-v6;
return v7;
}
</script>
</head>
write a program add two number and print using java script?
<html>
<head>
<script language="JavaScript" type="text/JavaScript">
var v4=10; //global variable
Function fnadd(v1,v2)
{
var v3=v1+v2;
return v3;
}
Function fnadd()
{
var res=f1(2,3);
document.write(res);
alert(res);
}
</script>
</html>
Creating Array using java script
<script language="JavaScript" type="text/JavaScript">
var sname=new array();
sname[0]="ritesh";
sname[1]="rakesh";
sname[2]="sss";
sname[3]="shakti";
Function fnprint()
{
debugger; // its like break point(but we have to setting in browser[tool-internet-option-advance- disable - //script debug chose internet option)
for(i=0; i<sname.length;i++)
{
alert(sname[i]);
}
</script>
var person=new Object();
person.firstname="John";
person.lastname="Doe";
person.age=50;
person.eyecolor="blue";
document.write(person.firstname + " is " + person.age + " years old.");
</script>
var sname=new array();
sname[0]="ritesh";
sname[1]="rakesh";
sname[2]="sss";
sname[3]="shakti";
Function fnprint()
{
debugger; // its like break point(but we have to setting in browser[tool-internet-option-advance- disable - //script debug chose internet option)
for(i=0; i<sname.length;i++)
{
alert(sname[i]);
}
</script>
Creating JavaScript Objects
<script>var person=new Object();
person.firstname="John";
person.lastname="Doe";
person.age=50;
person.eyecolor="blue";
document.write(person.firstname + " is " + person.age + " years old.");
</script>
If...else Statement
<script>
function myFunction()
{
var x="";
var time=new Date().getHours();
if (time<20)
{
x="Good day";
}
else
{
x="Good evening";
}
document.getElementById("demo").innerHTML=x;
}
</script>
function myFunction()
{
var x="";
var time=new Date().getHours();
if (time<20)
{
x="Good day";
}
else
{
x="Good evening";
}
document.getElementById("demo").innerHTML=x;
}
</script>
If...else if...else Statement
if (time<10)
{
x="Good morning";
}
else if (time<20)
{
x="Good day";
}
else
{
x="Good evening";
}
{
x="Good morning";
}
else if (time<20)
{
x="Good day";
}
else
{
x="Good evening";
}
exception handling in javascript
<!DOCTYPE html>
<html>
<head>
<script>
var txt="";
function message()
{
try
{
adddlert("Welcome guest!");
}
catch(err)
{
txt="There was an error on this page.\n\n";
txt+="Error description: " + err.message + "\n\n";
txt+="Click OK to continue.\n\n";
alert(txt);
}
}
</script>
</head>
<body>
<input type="button" value="View message" onclick="message()" />
</body>
</html>
<html>
<head>
<script>
var txt="";
function message()
{
try
{
adddlert("Welcome guest!");
}
catch(err)
{
txt="There was an error on this page.\n\n";
txt+="Error description: " + err.message + "\n\n";
txt+="Click OK to continue.\n\n";
alert(txt);
}
}
</script>
</head>
<body>
<input type="button" value="View message" onclick="message()" />
</body>
</html>
No comments:
Post a Comment