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 – alert(), confirm() and prompt()

Historically these statements were amongst the first ones taught to students learning JavaScript. In the early Netscape days with no way to properly interact with the web page itself those were the only ways to interact with your visitor. With the introduction of the Document Object Model these modal dialogs became unnecessary and some browsers […]

Bad Bits – Function Statements

While function statements are the most popular of the three ways of defining functions in JavaScript, there are a number of limitations in how they can be used. Using anonymous functions as the values assigned to variables are just as easy to code and far more flexible in how they can be used so for […]

Bad Bits – Bitwise Operators

In most other programming language the bitwise operators are so much more efficient than the alternatives that their efficiency makes up for making the code harder to read and maintain. In most versions of JavaScript these operators are far less efficient than the alternatives and even in those modern implementations where they are more efficient […]

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 […]

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.