When HTML is not enough – JavaScript

JavaScript is, as the name suggests, a scripting language. Used in conjunction with HTML and other technologies (such as PHP), it allows the developer to create extremely powerful interactive websites.

What’s in a name?

JavaScript is often confused with Java, but the two are not related in any way other than by name. Java was developed by Sun Microsystems (and now Oracle) as an object-oriented programming language. JavaScript was initially developed by Netscape, and is an object-oriented *scripting *language. The major difference here is in the way the code is executed – Java requires the code to be written, compiled, and then run through a virtual machine (or VM) in an effort to make the program platform independent. If there’s a VM for your operating system, you can (in theory) run any Java program on it.
Javascript, on the other hand, is an interpreted scripting language. The code is stored in plain text, and commands are executed as needed, without pre-compilation. JavaScript has in some ways achieved what Java set out to do – it runs on any platform that has web browser support for JavaScript.
Java and Javascript do support similar syntax and libraries, but that is where the similarities end.

Where did JavaScript come from?

Java, the programming language, was created in the early 1990s under a variety of different names. The language was designed to have a similar syntax to C and C++ to give programmers a head start when using it. Java had become a very well-known language at the time, as it was usable on multiple platforms.
Microsoft had already implemented several web programming and scripting languages and technologies, and Netscape wanted to compete on even terms. Netscape needed a scripting language that complemented Java, and so JavaScript, the scripting language, was developed independently in 1995 under the name Mocha.
The language was included in web browser Netscape Navigator 2.0 as “LiveScript” in the beta versions, and renamed JavaScript on launch of the final version. The general consensus is that the language was renamed in such a way to imply it was directly connected to Java, and therefore build a reputation quickly.

What can JavaScript do?

Many websites make use of JavaScript these days, as it is almost essential for complex interactions. The Gmail system makes extensive use of JavaScript to present it’s interface, and is one of the more complicated examples of JavaScript code. A far simpler example is hidden on many web pages – back end code that records visitor information for analytics purposes.
Many conditions can be used to execute JavaScript, including page loads, link or button clicks, a pointer being placed over a specific area, and so on, making it ideal for use on interactive sites, rather than those that just present information. It can also be used in conjunction with other languages, such as PHP, in order to access databases and perform actions on them. In this way, platforms such as WordPress can create an entirely database-driven site with a backend, frontend, and a theme engine, allowing users to create content with the minimum of fuss, but with great use of technology.

Where does it run?

Standard JavaScript runs on the end-user computer via a code interpreter built into the browser. Versions of JavaScript that run on the server have been developed, including Microsoft’s JScript and the framework node.js. Netscape developed a server-side version that ran on Netscape Enterprise Server, now Oracle iPlanet Web Server.
JavaScript is often included in the header of an HTML file, either as straight text or as a link to a separate .js file. This method can be used if the same code is to be used on multiple pages as an optimization technique, or as a method of keeping HTML and JavaScript code separate.

Libraries and frameworks

As with all coding platforms, there’s no point reinventing the wheel, and so libraries and frameworks are available to enable easy development of complex websites.
There is no standard library of functions or features as included in other languages – “stdlib” does not exist. However, a third-party open source Stdlib is in development, and will offer a collection of libraries for mathematics, statistics, data processing, and streams, along with many of the utilities expected in a standard library.
Additionally, there is no standard way to output plain text from JavaScript, other than directly through the console. A simple “Hello World” may not be as easy as you may think in pure JavaScript, but bear in mind the JavaScript is often contained within HTML. Display text in HTML is just as simple as including it within the file.
There are other third-party libraries and frameworks available. Here are a few:

React

Used by Facebook among others, React is ideal for designing interactive user interfaces.

jQuery

Often used for AJAX (Asynchronous JavaScript And XML) programming, allowing processing of tasks in the background, eg database queries for filling in search boxes as you type.

AngularJS

This is a framework, often used for single-page sites. It provides a skeleton site for you to begin with, and makes prototyping much easier.

VueJS

A lightweight framework, suitable for designing user interfaces easily.

Is JavaScript the right choice for your project?

In most cases, the answer is a resounding **yes **if you need any sort of interactivity within your site. All modern web browsers support an implementation of JavaScript, and so coding in JavaScript means you can have your site work cross-platform and with little fuss. There are no special server requirements, as JavaScript is stored in plain text and runs on the client (browser) side. It is relatively lightweight, and easy to learn especially if you have had experience of other object-oriented languages.
The only potential downside is if you expect your site to be used on older browsers, as the language has evolved and been updated over time. However, as long as your visitors are using a browser written within the last ten years or so, everything should be fine!

Leave a Reply