Internet Programming CH-4
Internet Programming CH-4
JAVA SCRIPT
Introduction
JavaScript is a popular web-page scripting language, and is supported by almost every
browser.
It adds interactivity to web technology pages.
JavaScript is usually embedded directly into HTML pages.
It is very powerful client-side scripting language. it is mainly for enhancing the
interaction of a user with the web page.
It is also being used widely in game development and mobile application development.
Why study javascript?
javascript is one of the 3 language all web developer must know: Basically
1.HTML:- to define the contenet of web pages.
2.CSS:- to specify the layout of web pages.
3. javascript:- to program the behavior of web pages.
JAVA SCRIPT…
So, JavaScript is a client-side scripting language that runs entirely inside the web
browser.
Javascript and Java are completely different language, both in concept and
design.
</body>
</html>
JAVA SCRIPT…
3. In an external file (with extension .js)
<html>
<body>
<script type="text/javascript" src="my.js"></script>
</body>
</html>
Syntax
// defining a function
function <function_name>()
{
//code to be execute
}
// calling a function
<function_name>();
JAVA SCRIPT FUNCTIONS…
Function Parameters:- a function can have one or more parameters, which will be
supplied by the calling code and can be used inside a function.
Javascript is a dynamic type scriptin language, so a function parameter can
have of any data type.
Syntax
function showmessage (firstname, lastname)
{ Is a box with OK button
alert (“Hello” + firstname+” lastname);
}
JAVA SCRIPT FUNCTIONS…
Eg 1.
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
function showmessage (firstname,lastname)
{
alert ("Hello" + firstname + ""+ lastname);
}
showmessage ("Abigiya","Mesfin")
showmessage ("Eden","Mesfin")
showmessage ("8","21")
</script>
</body>
</html>
JAVA SCRIPT FUNCTIONS…
Eg 2.
<html>
<body>
<script type="text/javascript">
function addition(){
var x=7;
var y=10;
var sum=x+y;
alert(sum);}
</script>
<form>
<input type="button" onclick="addition()" value="show">
</form>
</body>
</html>
JAVA SCRIPT ARRAYS
Array is a grouping of objects.
It stores multiple values in a single variable.
It stores a fixed size sequential collection of elements of the same type.
It is used to store collection of data.