Professional Documents
Culture Documents
Java Script Is A Browser
Java Script Is A Browser
to build interactivity into HTML pages. In other words, it is written directly into the HTML web pages and
is interpreted and executed in response to some activists on the page such as when loading or when a
button is clicked. Java script interacts with the browsers and can read information of the web page e.g.,
the data entered in the form.
It is case sensitive
ADVANTAGES
• Is easy to learn and user friendly because it has increased interactivity, you can create interfaces
that react when the users hover over them.
• Has less server interaction. One can validate user input before sending the page of to the server,
which means less load on the server.
• It is embedded in html and uses small routine or tasks to create special effects.
• Richer interfaces, JavaScript can include items such as drag and drop components to give a rich
interface to the site visitors.
LIMITATIONS
Js has development tools that can help one develop the course.
• Editor which is the notepad when you can develop the js code
• Microsoft front page which provides web developers with a number of js tools to assist in the
creation of an interactive website.
• Micro media dream weaver – provides prebuilt js components that integrates well with the
databases.
• Micro media home site- provides html and js editor which manage personal websites.
Js variables
Variables are simply named containers that hold data. Variables in js are declared with the
keyword var. E.g.
Var num1, var num2, Var total
When naming variables the following rules must be taken into consideration
1. You should not use any js reserved words . e.g. break , true , Boolean are not valid
names.
2. Variables names should not start with a numeral e.g. 0-9 , must begin with a letter or
underscore character.
3. They are case sensitive. E.g name and name are different variables .
4. Variable scope. Scope of a variable is the region in each a variable are defined. Js has
two scopes. Global variable which means it is defined to be used everywhere in your js
code. Local variable is visible only within a function where it is defined
JS RESERVED WORDS
This are words that cannot be used as js variables, functions, methods ,loop ,labels or object names.
Some of them include, var, void ,while, switch, this , throw, return, long, int, for , function, go to, car,
break, case , continue ,do ,double etc,
JS DATA TYPES
Numbers which are represented in the step and can also read octal and hexadecimal.
Operators used in js
Include arithmetic operators which include plus , minus, multiplication, increment, decrement
Comparison operators which acts as and equal sign = , Not equal, greater or equal, less or equal.
Assignment operators include equal, plus, equal, minus equal, multiplication equal, less equal
DISPLAYING OF VARIABLES IN JS
Variables can be displayed in text boxes or forms in the dialog boxes, document.write or print
statement
This statement will display the value of the sum or the total on page.
Variables can be declared and assigned values directly.
e.g.
<!DOCTYPE html>
<html>
<head>
<title>js</title>
<script type="text/javascript">
var x= 200;
var y= 300;
var total=x+y;
</script>
</head>
<body>
</body>
</html>
Alert keyword can also be used to display the information in the screen.
To receive variable In a dialog box , the keyword prompt is used in the statement, and parse int is used
in the statement to convert a sequence of characters into its integer values.
e.g.
alert (sum)
<!DOCTYPE html>
<html>
<head>
<title>js</title>
<script type="text/javascript">
var average;
</script>
</head>
<body>
</body>
</html>
Control structures are used to determine program flow or order in which the instruction are carried out.
Control structures mainly us comparison operators, they are operators used to compare the content of
variables with the values of others. They also use the logical operators used to check if a variable fall into
a range of values.
The control structures use the conditional statements and the conditional statements includes
e.g.
if the age is less than 18 , then display you are too young, else if greater than 18, you are too old.
<!DOCTYPE html>
<html>
<head>
<title>js</title>
<script type="text/javascript">
if(age<18){
}else if(age>=18){
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Colors </title>
<script type="text/javascript">
if (colors=="green"){
alert("Or country");
}else if(colors=="black"){
alert("too dark");
alert("Danger");
else{
alert("Not available");
</script>
</head>
<body>
</body>
</html>
Case statement is used instead of the if then if statement
Case statement
Switch (expression)
{case1:statemet
Iterations mainly uses loops and loops enables a statement to be repeated several times
There are various types of loops or iterations statements that can be used. This include
For loop
Loops can be nested with the inner loop running the full force each time the program .
For(row=1;row<=10; row++)
WHILE LOOP
Can also be used to repeat a number of statements. If the condition is met at the start of the loop. The
statements are not executed at all, its main aim is to execute a statement of code repeatedly as long
as the expression is true. Once expression becomes false. The loop exits .
While(statement)
increment
e.g.
Count++
Do while loop performs its tests after the enclosed statement, its syntax is as follows
Do{
Statement
While (test)
Var i = 10