JavaScript Chapter 1
Chapter 1
Javascript: An Overview
1.1 What is Javascript?
JavaScript is a high-level, dynamic, untyped, and interpreted programming language. It has been standardized in the ECMAScript
language specification. Alongside HTML and CSS, it is one of the three essential technologies of World Wide Web content
production; the majority of websites employ it and it is supported by all modern web browsers without plug-ins or any kind of
other extension.
JavaScript is prototype-based with first-class functions, making it a multi-paradigm language, supporting object-oriented, imperative,
and functional programming styles. It has an API for working with text, arrays, dates and regular expressions, but does
not include any I/O, such as networking, storage or graphics facilities, relying for these upon the host environment in which it is
embedded.
So, to conclude this paragraph, keep in mind answers to the question "What is Javascript?"
It is a programming language. It is an interpreted language. It is object-based programming. It is widely used and supported It is
accessible to the beginner.
1.2 Javascript Code Implementation
1.2.1 Implementing Javascript
There are three ways to add JavaScript commands to your Web Pages:
• Embedding code
• Inline code
• External file
1.2.2 Writing Javascript
JavaScript code is typically embedded in the HTML, to be interpreted and run by the client’s browser. Here are some tips to
remember when writing JavaScript commands.
JavaScript code is case sensitive White space between words and tabs are ignored Line breaks are ignored except within a
statement JavaScript statements end with a semi-colon: ;
1.2.3 Objects
JavaScript supports programming with objects. Objects are a way of organizing the variables. The different screen elements such
as Web pages, forms, text boxes, images, and buttons are treated as objects. Every object has its own properties and methods.
Properties define the characteristics of an object. Examples: color, length, name, height, width Methods are the actions that the
object can perform or that can be performed on the object. Examples: alert, confirm, write, open, close .
1.3 Javascript Events
The objects in a Web page are organized in a hierarchy. All objects have properties and methods. In addition, some objects also
have "events". Events are things that happen, usually user actions, that are associated with an object. The "event handler" is a
command that is used to specify actions in response to an event. Common events are:
• onLoad - occurs when a page loads in a browser
• onUnload - occurs just before the user exits a page
• onMouseOver - occurs when you point to an object
• onMouseOut - occurs when you point away from an object
• onSubmit - occurs when you submit a form
• onClick - occurs when an object is clicked
JavaScript’s interaction with HTML is handled through events that occur when the user or the browser manipulates a page. When
the page loads, it is called an event. When the user clicks a button, that click too is an event. Other examples include events like
pressing any key, closing a window, resizing a window, etc.
Developers can use these events to execute JavaScript coded responses, which cause buttons to close windows, messages to be
displayed to users, data to be validated, and virtually any other type of response imaginable. Events are a part of the Document
Object Model (DOM) Level 3 and every HTML element contains a set of events which can trigger JavaScript Code