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 ECMAScript 5 in 2011 are being added to the site where they are supported by the latest version of all popular browsers. 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.

A few examples of what we can expect from EcmaScript 6 are also included in their own section so you can see the direction that JavaScript is moving in - even though it will probably be quite a while before we can use those commands.

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 – Switch Fall Through

While not as obvious as some of the other bad bits of JavaScript, allowing a switch statement to fall through from code before a case label to code after that label in JavaScript is completely unnecessary. While it may occasionally be done in some other languages as an efficiency hack, the efficiency gains achieved by […]

Bad Bits – eval()

Perhaps the worst command that exists within JavaScript is eval(). Almost every instance where people use it the code can be easily rewritten to do away with it without significantly changing the length of the code but with dramatic improvements to its efficiency. Strict JavaScript makes this command slightly more efficient by applying restrictions on […]

Bad Bits – with

The inclusion of the with command in JavaScript was a complete mistake. This has now been rectified and using this command in strict JavaScript will now produce a syntax error.

Bad Bits – == and !=

JavaScript has two different sets of equality/inequality comparison operators. The shorter ones shown should be avoided as much as possible as they provide plenty of opportunity for values to be considered to be equal when they are not and in some instances will provide a different answer to what the same comparison would give in […]

Bad Bits – Floating Point

The problem with Floating Point numbers applies to all programming languages and not just JavaScript but as JavaScript is often the first language that people have learnt it is often the first place that the limitations of floating point numbers catch people out. The most common situation that catches people out is dealing with currency. […]

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.