Professional Documents
Culture Documents
SCRIPTING LANGUAGE
JAVA SCRIPT
FEATURES OF JAVASCRIPT
JS in head : placed in head when you performsome action such as click of submit button or link.
JS in body : this will execute when a web page start loading in a web browser.
JS in external file : when code is lengthy and for code reusability. Added using src attribute.
1. Lexical structure: provide set of rules to write program, defines rules for variable name,
writing comments, procedure to seprate one statement with other. Define rule for following
character set: total 128, 96 characters availabe, 32 reserved control charcters. \t,\f,\b,\n,\,\\
case senstivity: marks, Marks, MARKS all are different words.
white space and line break: matters in case ofstrings and regular expressions.
optional semicolon
comments: // single line comments /*multiple line comment*/
literal :
1. numerical decimal(89,569), octal(021,065), hexadecimal(0x5673)
2. floating point - 4.987, -123.5679, 0.98
3. boolean true or false
4. string - akhil or 'akhil'
5. array declared in [ ] brackets. var emp=['a','b','c']
6. regular expression RegExp used to match a character or string.
7. object literal collection of name-value pair enclosed in { } separated by , .
identifier
1. must start with letter, $ , _ .
2. cannot start with number.
3. any length.
4. case sensitive
5. cannot contain reserved words.
reserved words
1. already defined in javascript.
2. Exploring variables
data stored in variables.
Variable has name, value and address
name uniquely identify variable, value refers to data,memory refers to memory location of
variable.
Declaring a variable using var keyword: var abc
3. Exploring operators
+ , - , * , % ,++ , --, += , -= , == , && , !! and many more
1. adding script in head, body and using an external java script file
<html>
<head>
<script type="text/javascript" >
document.write("written in head of the page");
</script>
</head>
<body>
<script type="text/javascript" >
document.write("<br>written in body of the page<br>");
</script>
var a=10;
for(i=0;i<5;i++)
{
a=a+1;
}
document.write(a);
<html>
<body>
<hr>
<script type="text/javascript" >
document.write("Simple value printing <br><br>");
var a=10;
document.write("Value of a = "+a);
</script>
<hr>
<hr>
</body>
</html>
3. Alert box
<html>
<body>
<script type="text/javascript" >
alert("hello i am in alert");
</script>
</body>
</html>
4. Confirm box
<html>
<body>
<script type="text/javascript" >
var q=confirm("Press any one button ")
if(q)
{
document.write("you pressed ok");
}
else
{
document.write("you pressed cancel ");
}
</script>
</body>
</html>
5. Prompt box
<html>
<body>
<script type="text/javascript" >
var n= prompt("enter name");
document.write(n);
</script>
</body>
</html>