What is JavaScript?

JavaScript is a programming language (or more accurately a scripting language) used to create client-side scripts. A client-side script is a block of programming code that is embedded in a web page and executed by a web browser. It differs from a server-side script in that the script's code will run on the client computer rather than on a web server.

Although there are a number of client-side scripting languages that can be used with web pages, we will be working with is JavaScript because it is by far the most widely-used client-side scripting language. It can either be embedded directly into an HTML document, or stored in a separate JavaScript source file. JavaScript source files are plain text files with their own special file extension (.js).

In the early days of the World Wide Web, web pages were static documents that contained hypertext - essentially text that contained links (sometimes called hyperlinks) to other web pages or image files. It soon became possible to display images directly within the browser window along with the text, but web pages were still essentially static affairs. The only "interactive" elements were the hyperlinks.

Then, in 1993, the Common Gateway Interface (CGI) was introduced. CGI was a technology that allowed messages (called queries) to be sent from a web browser running on a client computer to a computer program (called a script) that ran on the web server. A query would typically consist of data entered into an HTML form by the user, and would be sent to the server when the user clicked on the form's "Submit" button.

The script would carry out any processing required, which often involved interrogating a database on the server to retrieve information requested by the client, and formulate a response. The response took the form of a dynamically generated HTML document, which was sent back to the client computer. The dynamically generated page would then be displayed by the client's web browser, replacing the page that originally generated the query.

Of course, all of this took time. Broadband connectivity would not be available to most Internet users for some years to come. When a user clicked on a button or link to generate a query, there would often be a considerable delay before the response appeared on their screen. Indeed, the very existence of CGI technology increased the workload on the average web server to such an extent that server response times generally were adversely affected.

The increased delays in response times led to the World Wide Web being referred to by many as the "World Wide Wait". The obvious answer, of course, was to increase connection speeds and improve the capacity of web servers to enable them to cope with the increased workload, but this would not happen overnight.

In the meantime, two things became apparent. The first was that scripts in general could do a lot more than just generate responses to database queries. They could, in theory at least, provide the same kind of functionality as a fully-fledged computer program running on the client computer. The second thing that became apparent was that at least some of this functionality could be carried out on the client computer, without the need to send queries to the server.

What was needed was a scripting language that would work with a web browser and run on the client computer. The answer came in the form of JavaScript, which was created in 1995 for the Netscape Communications Corporation by US software engineer Brendan Eich. The language was originally called Mocha, but its name was changed - first to LiveScript, and shortly thereafter to JavaScript.

The history of how JavaScript has evolved, interesting as it may be, is something we're not going to delve into here in any detail. Suffice to say that, in its early days, JavaScript's development was shaped by a collaboration between Netscape and Sun Microsystems who, in a move designed to protect their mutual interests from corporate rivals such as Microsoft, started a standardisation process. As a result, JavaScript has become the de-facto client-side scripting language of the web, and has survived all attempts to supplant it.

JavaScript works by interacting with the Document Object Model (DOM), which you can think of as a web document's application programming interface (API). This sounds quite complicated, but it essentially just means that every element and node in a web page can be addressed by a script in order to make something happen, like changing the appearance of the page in some way. JavaScript can also detect and react to events like button clicks and mouse-overs, or a document being opened. We'll look at the DOM in a bit more detail elsewhere.

JavaScript is typically used to enable various kinds of interaction between web pages and users. Interesting visual effects like rollovers, transitions, and animation are all fairly commonplace, but JavaScript also has more serious uses. For example, a script can be used to validate the data entered into a form by a user. The script checks to make sure that all of the required fields have been completed, and that the data is correctly formatted, before the contents of the form are submitted to the web server.

In order for a client-side script to be able to execute on the client computer, two conditions must be met. First of all, either the user's web browser must support the scripting language used to write the script, or the user must have the necessary plug-in or helper application installed in order to enable the browser to interpret the script. One advantage of using JavaScript is that all modern browsers have built-in support for it.

The second condition is that browser support for the scripting language has not been disabled by the user. Most web browsers allow users to disable support for client-side scripting by making changes to the browser's default settings. While some users may opt to do this due to security concerns, our (admittedly somewhat limited) research suggests that the average number of users worldwide who have disabled JavaScript is somewhere in the order of 0.2%.

You may well be of the opinion that the benefits of using a scripting language like JavaScript outweigh any possible security concerns, but keep in mind that not all potential visitors share this view. Client-side scripts can certainly make your pages more interactive, and thus more likely to engage your visitors, but your pages should be able to function as documents even if scripting is not supported by the user's browser, or has been disabled by the user.

Perhaps the best thing about JavaScript is that you don't need any additional software. Client-side scripts can be created using your favourite HTML or text editor. JavaScript code can be embedded directly within your HTML documents, or stored in a separate file that can be referenced by any number of HTML documents. The JavaScript programmer also has many additional tools at their disposal, including a number of JavaScript libraries and frameworks that assist with the task of designing and developing sophisticated web applications.

JavaScript is an implementation of ECMAScript - a scripting language specification developed by the ECMA (European Computer Manufacturers Association) International standards organisation with the aim of standardising independent JavaScript implementations. The ECMAScript standard was first published as ECMA-262 (ISO/IEC 16262) in June 1997. At the time of writing, the most recent version of the standard is the tenth edition, published in June 2019, which is formally known as ECMAScript 2019 (ES2019).