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.

Array range

When we load up values into an array we do not necessarily want them to all be positive integers starting from zero as the populate method adds. This range method allows us to specify the start and end integers we want the array to contain.

Eliminate Duplicates

Just by using one JavaScript array method to convert the array to an object and on JavaScript object method to convert back to an array we can easily remove all duplicate entries from the array.

Array Populate

Simply creating an array doesn’t give values to the entries in the array – or rather the entries are all undefined. Most of the array methods will automatically skip over undefined entries and so cannot be used to process an array where all of the entries are undefined. One simple solution is to populate the […]

Array hasIndex

If we use a for or while loop to process an array then if it is a sparse array with missing entries within the loop range then the loop will fail. If instead we use a loop then we not only process the array entries, we would also process any enumerable properties and methods […]

Array.setMax, Array.setMin and Array.integer

Sometimes we want numbers that are within a given range. While we can easily use comparison tests to determine if a single number is inside the range and adjust it to the boundary value iof it isn’t, it gets a bit more involved if the numbers are in an array (particularly where not everything in […]

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

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.