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.

Functions

Our next two homework questions look at functions. The first question shows some code where we have a simple function that calculates the square of a number. The rest of the code is processing a loop to display a table of numbers and their squares. You are asked to work out how the loop could […]

If Statements and Arrays

The next pair of homework questions test for a basic knowledge of if statements and arrays. The first question involves setting up an array of capital cities for a country and then testing if a value entered is or is not a capital city. The answer that I provide uses the Australian capital cities but […]

Variables, Operators, and Loops

The sorts of homework questions that I see people asking for help with on various forums demonstrates quite clearly that they are being taught JavaScript for the 20th Century and the Netscape browser rather than how to write JavaScript properly. The same questions keep turning up over and over with the same obsolete code being […]

Canvas – 3d

All of the examples we have looked at using canvas have involved just two dimensions. A canvas can also create 3d effects. Doing so involves a lot more calls though and so most people looking to achieve 3d canvas effects would use one of the several libraries that have been created to handle 3d processing […]

Canvas – Animation

Animating the content of a canvas is slightly easier to do than to apply animations without the canvas (even where you do have library calls to take care of most of the animation for you).

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.