Most of the internet applications are built using many interoperable languages; hence HTML alone will not be sufficient in making these web applications interactive.
HTML is static, so you cannot have loops, variables, and interactive functionality. But HTML being a static language, it can be
easily incorporated with different languages to develop a complex page.
In this post, we will cover an scripting language that is JavaScript. JavaScript is one of the most powerful languages used in web development.
This article contain introduction to JavaScript, basic programming concepts
like variable declaration, data types, operators, looping statements,
functions and JavaScript objects.
Introduction to JavaScript Programming
Java script is a programming language with direct support to object oriented
methodologies. We can use JavaScript to perform a variety of functions on
your website. Some of the functions are just functional, while the others are
greater in nature, providing interactivity for our website visitors.
JavaScript gives HTML designers a programming tool –
HTML authors are normally not programmers, but JavaScript is a scripting
language with a very simple syntax. Almost anyone can put smal
“script” of code into their HTML pages.
JavaScript can react to events –
A JavaScript can be set to execute
when something happens, like when a page has finished loading or
when a user clicks on an HTML element.
JavaScript can read and write HTML elements –
A JavaScript can read and change the content of an HTML element.
JavaScript can be used to validate data –
A JavaScript can be used
to validate form data before it is submitted to a server. This saves the
server from extra processing.
JavaScript can be used to detect the visitor’s browser
JavaScript can be used to detect the visitor’s browser, and depending on
the browser-load another page specifically designed for that browser
JavaScript can be used to create cookies –
A JavaScript can be used
to store and retrieve information on the visitor’s computer.
Utility of JavaScript
We are building more and more complex web applications these days and
high interactivity either requires Flash (plugins) or scripting. JavaScript
disputably the best way to go, as it is a web standard, it is supported
natively across browsers (more or less some things differ across browsers).
and it is compatible with other open web standards.
JavaScript is very easy to implement. All you need to do is put your code
in the HTML document and tell the browser that it is JavaScript
JavaScript works on web users computers even when they are offline
- JavaScript can help fix browser problems or patch holes in browser
support for example fixing CSS layout issues in certain browsers.
JavaScript allows you to create highly responsive interfaces that
improve the user experience and provide dynamic functionality, without
having to wait for the server to react and show another page- JavaScript can load content into the document if and when the user
needs it, without reloading the entire page
Evolution of the Java Script language
Around 1992, a company called Nombas began developing an embedded
scripting language called C-minus-minus (Cmm for short). The idea behind
Cmm was simple: a scripting language powerful enough to replace macros,
but still similar enough to C (and C++) that developers could learn it quickly.
As World Wide Web gained popularity, a gradual demand for client-side
scripting languages developed. At the time, most Internet users were
connecting over a 28.8 kbps modem even though Web pages were growing
in size and complexity. Adding to users’ pain was the large number of
round-trips to the server required for simple form validation. Imagine filling
out a form, clicking the Submit button, waiting 30 seconds for processing,
and then being encountered with a message telling you that you forgot to
complete a required field. Netscape, at that time on the cutting edge of
technological innovation, began seriously considering the development of a
client-side scripting language to handle simple processing.
Brendan Eich, who worked for Netscape at the time, began developing a
scripting language called LiveScript for the upcoming release of Netscape
Navigator 2.0 in 1995, with the intention of using it both in the browser and
on the server (where it was to be called LiveWire). Netscape entered into a
development alliance with Sun Microsystems to complete the
implementation of LiveScript in time for release. Just before Netscape Navigator 2.0 was officially released, Netscape changed the name to JavaScript in order to capitalise on Java as a new Internet buzzword.
JavaScript Versions and Browser Support
The first browser to support JavaScript was Netscape Navigator 2.0 beta
version. Below is the list of JavaScript versions and supported browser
versions.
- JavaScript 1.0:- supported by Netscape navigator 2.0 and
Internet explorer 3.0 (1996) - JavaScript 1.1:- supported by Netscape navigator 3.0 (1996)
- JavaScript 1.2:- supported by Netscape navigator 4.0 (1997)
- JavaScript 1.3- supported by Netscape navigator 4.06 and
Internet explorer 4.0 (1998) - JavaScript 1.4:- supported by Netscape navigator server
- JavaScript 1.5:- supported by Netscape navigator 6.0 and
Mozilla Firefox 1.0 and IE 5.5 to IE 8 (2000)
Unit 11 - JavaScript 1.6-supported by only by Mozilla Firefox 1.5 (2005)
- JavaScript 1.7-supported by Mozilla Firefox 2.0 (2006)
- JavaScript 1.8.1:- supported by Mozilla Firefox 3.6 (2009)
- JavaScript1.8.5:- supported by Mozilla Firefox 4.0 and IE9 (2010)
Client-Side JavaScript vs. Server Side Java Script
There are two major types of JavaScript namely:
Client-Side JavaScript (CSJS):
Client side Java script comprises the basic language and predefined objects
which are relevant to running Java script in a browser. The client side java
script is embedded directly by in the HTML pages. This script is interpreted
by the browser at run time. It is JavaScript that enables the web pages on
browsers to run active online content.
Server-Side JavaScript (SSJS)
Server side Java script also resembles like client side java script. It has
relevant java script which is to run in a server. The server side java scripts
are deployed only after compilation. It is JavaScript that enables back-end
access to databases, file systems, and servers.
Programming with Javascript
Javascript can be used in different ways within an HTML file.
1. Header Scripts
Javascript is embedded between <SCRIPT> tags within the <HEAD> tag and is used for initialising variables and or create functions that can be called from anywhere of the entire script. JavaScript in header is executed once when the page loaded.
2. Body scripts
In body script, JavaScript is embedded between <SCRIPT> tags within the<BODY> tag. JavaScript within the body tags are used for handling various events.
3. Called directly when certain events occur
In this type, JavaScript are called when certain events occur. Examples of events include onLoad, onClick, onError, onSelect, onSubmit, onChange etc.