What is JavaScript?

Firstly let’s define what a script is before we learn about JavaScript.

A script is a set of instructions given to a browser/server that is essentially an “active” command, in other words, it does things instead of just static HTML element. Let’s go through a few examples:

lets say you want to contact a webmaster to ask a question, most of the time you’ll be presented with a form to fill out. When you have finished filling out the form, there will be a button that says “Submit” or “Send” (see figure 1.a below), when you click this button all the information in the form is sent to a script that lives on the web server. This script will (among other things) make a record of your details in a database, format the data into an email and send it to the webmaster. This type of script is called a form processor and is also an example of a Server side script because all the actions takes place on the web server.

Example form that uses JavaScript for form field validation

Now lets take the same situation except this time you forget to choose your country and it is left on “Please Select”, you click the Submit button, but instantly there is a little alert box advising you of your mistake (see figure 1.b below). This is JavaScript and is an example of Client side scripting because this action takes place inside your browser, not the server.

Example of a JavaScript alert box activating during form validation

JavaScript

As you have probably guessed, JavaScript is a client side scripting language processed by your browser. Most browsers have a built-in JavaScript “Engine” or interpreter that reads the instructions given on a webpage and acts upon them. The script in the last example basically said If the user forgets to enter their country, make an alert box and tell them of their mistake.

JavaScript can do a lot more too, for instance: validate forms, visual effects like fade, grow and blind, rollover menus and with Ajax pretty much anything. JavaScript is also quite easy to program, has been around since the mid 90’s and is widely used, so that’s why you have probably heard about it. You’ve the option to turn JavaScript on or off in your browser and by default most browsers have it enabled, however it’s recommended that you leave it enabled so you can enjoy all the web has to offer. If you need help checking your browsers JavaScript status, visit our guide on how to enable or disable JavaScript.

This guide’s intended to give a conceptual overview of JavaScript, if you’re interested in studying it just visit W3Schools for complete tutorials and reference.