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.


Phone numbers are a bit different from other numbers in that a leading zero needs to be retained. Different parts of the world apply different formatting to phone numbers but for the purpose of saving the numbers we can save space by removing any such formatting (we can add it back when we display the […]


We have already looked at how to convert text strings into dates. Another “type” conversion that we might need is one that converts text into numbers remebering that we need to strip out any formatting in order that the numbers can be used for calculations.

String.addSlashes and String.stripSlashes

JavaScript isn’t the only programming language that there is and sometimes we will come across functionality that some other language has that we decide would also be useful in JavaScript. Two such calls in PHP are those that add and remove the backslashes that escape certain characters so as to avoid those characters being misinterpreted. […]


The JavaScript String object has predefined methods for converting all of the text to lower case or upper case. We can make use of this to simplify any conversions to title case (where the first letter of each word is converted to upper case). We can even provide an option to decide whether the rest […]


Any values that are entered into a form on a web page are made available to JavaScript as text strings. Sometimes these fields are really intended for entering something other than text and so we need to convert the text into that something else. We can make the conversion of text strings into dates much […]

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

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.