Css 1
Css 1
Introduction
JavaScript is a lightweight language
Features of JavaScript
It is most popular scripting and programming language
Advantages of JavaScript
Less Server interaction
Increased connectivity
Includes items as drag & drop components and sliders to give a Rich Interface to website
Program in JavaScript
Following program will print "Hello World!!!" on browser using HTML and JavaScript
<html>
<head>
<title>
</title>
</head>
<body>
<script>
</script>
</body>
</html>
Data Types
A value in JavaScript is always of a certain type. For example, a String or a number.
Any type of value can be stored in variable.
For Example
A variable can store String value at one moment and then it can be updated to a number
message= 1000;
Number
The number type represents both Integer and Floating point numbers, all the operations
associated with the Integer and floating point numbers are applicable to number data type.
Operation like Arithmetic, Relational, Assignment etc...
Example:
var num=200;
var value=12.90;
There are some "special numeric values" are associated with this data type is as follows
Infinity
-Infinity
NaN
These above data types are belongs to Number data type in JavaScript.
Infinity
1/0
For Example:
var x, y;
y = x/2;
String
A String in JavaScript is surrounded by quotes. There are 3 ways to assign String value to a
variable
Boolean
The Boolean type has only two values: true or false . This type is commonly used to store logical
values of types true or false / yes or no. These values are also generated from the operation like
Relational Operations or Comparison Operations.
For Example
var x = true;
var y=100;
x = y > 101;
above operation will update the value of x from true to false, as the comparison is wrong, it
will generate the value false.
Branching
if Statement
Syntax
if(expression)
if … else Statement
Syntax
if(expression)
{
else
if … else if … Statement
It allows JavaScript to execute the multiple statement as per the true expression
Syntax
if(expression)
else if (expression1)
else if (expression2)
else
switch Case
The switch case is used to evaluate an expression and execute several statements based on the
value of expression
The interpreter verifies the case against the value of the expression
If match is found with the case, then statement of the case executed
Syntax
switch (expression)
break;
break;
...
default: statement(s)
The purpose of the while loop is to execute the statements or code block repeatedly as long as
expression true.
Syntax:
while(expression)
The task of the while and the do … while is same, except that the expression check happens at
the end of the loop.
The loop will always be executed at least once, even if the expression is false.
Syntax:
do
{
Statement(s) to be executed;
} while (expression) ;
Semicolon is compulsory after while, so that the loop will get terminate if expression is false.
for Loop
• Loop Initialization: Initializes counter to a starting value, it executes before loop begins.
• Test Statement: Test expression, if expression is true it executes the code block of loop, if
false, it terminates the loop.
Syntax: