Introducing JavaScript

JavaScript has changed a great deal since it was first introduced but many sites still use outdated techniques. There are even lots of JavaScript tutorials on the web that show you how JavaScript should be written so that it can work in Netscape 2 rather than so that it will work in modern browsers. As a result there are many people who are writing what they think is JavaScript but where what they are producing is more suited to the 20th Century than to the 21st.

Beginners should work through all the basic examples prior to moving on to the other examples which cover separate aspects of JavaScript in more detail.

Most of the JavaScript examples here will work in IE5+, Opera7+ and all versions of Firefox, Safari and Chrome. Those commands introduced in ECMAScript5.1 in 2011 have been added (if I have missed any please let me know). Those commands introduced in ECMAScript2015 are currently being added (there are lots of them so it may take some time but then most current browsers do not yet support them all anyway). Where these new commands are not supported by IE8 or IE7 that information is included in the text since those two browsers might still have to many users for you to ignore. So few people using other browsers fail to keep their browser up to date that lack of support in older versions of other browsers will not have any significant affect.

There is a link to jsBin at the bottom right of all the pages. This site provides an easy way to test your JavaScript code online without needing to create an entire web page to run a simple test.

Bad Bits – document.write()

The introduction of the Document Object Model meant that the document.write() statement was obsolete. The only benefit that it had then was as a teaching tool prior to teaching the DOM. The introduction of innerHTML made even that use obsolete since innerHTML is as easy to use for beginner coding examples and has fewer restrictions […]

Bad Bits – href=javascript:

If you compare the code in the answers I show for the first of each pair of homework questions that are intended as a starting point for providing a proper answer to the second question in each pair, you will see that the code is significantly different from the way that many JavaScript beginners are […]

Regular Expressions

Here’s a pair of homewwork questions that might typically be asked early in a history of JavaScript course. The first is to generate a username needs to start with a letter, contain at least one number, and be at least 8 characters long. The answer that I provide for this question involves a single if […]

Document Object Model

These homework questions deal with the document object model and some of the ways that we can use it to interact with a web page.

Events

In this homework question we look at modern event processing. By combining the code from the event examples together we can perform our event processing without needing to add JavaScript all over the place in the HTML the way it used to be done.

This site is © copyright Stephen Chapman - Felgall Pty Ltd 2011-2016.

Privacy Policy | Terms and Conditions

You are welcome to use any the example JavaScript from this site in the scripts for your site or any that you develop for others but may not use the longer example scripts that contain a copyright notice in any other way without permission.