90
UNIT 4 INTRODUCTION TO JAVASCRIPT
Structure Page No.
4.0 Introduction 90
4.1 Objectives 90
4.2 JavaScript Variables and Data Types 2
42.1 Declaring Variables
4.2.2 Data Types
4.3. Statements and Operators
92
44 Control Structures 94
44.1 Conditional Statements
4.42 Loop Statements
4.5 Object-Based Programming 7
45.1 Funetions
452 Executing Deferred Scripts
453° Objects
4.6 Messagebox in Javascript
107
4.6.1 Dialog Boxes
4.62 Alert Boxes
4.63 Confirm Boxes
4.64 Prompt Boxes
4.7 Javaseript with HTML 109
47.1 Events
4.72. Event Handlers
48 Forms 12
Forms Array
4.9 Summary 119
4.10. Solutions! Answers 120
4.11 Further Readings 129
4.0 INTRODUCTION
JavaScript is the programming language of the Web. It is used mainly for validating
forms, JavaScript and Java can be related to each other. There exist many other
differences between the two, The client interprets JavaScript, whereas in Java, one can
execute a Java file only after compiling it. lavaSeript is based on an object model. In
this unit you will leam how to write JavaScript code and insert them into your HTML
documents, and how to make your pages more dynamic and interactive.
Besides basic programming constructs and concepts, you will also lear about Object-
based programming in JavaScript. We will also discuss some commonly used objects,
message boxes and forms. One of the most important parts of JavaScript is Event
hhandling that will allow you to write Event-driven code.
4.1 OBJECTIVES
After going through this unit you would be able to learn and use the following
features of the JavaScript:
fi Operators;
fi Loop constructs;
fi Functions;
AA Objects such as Math object, Date object;
AA Input and output boxes;Introduetion to
fi Event handlers;
SavaSeri
A) Form object; and a
fi Formarray,
4.2. JAVASCRIPT VARIABLES AND DATATYPES.
Let us first see the skeleton of a JavaScript file,
IGNOU