Learning JavaScript: Before You Start

To be able to write your own JavaScript you need the right tools for the job. The tools you need are readily obtainable via download and you can get everything you need without needing to pay for anything.

The first thing that you will need is an editor to write your JavaScript in. This needs to be a plain text editor and you probably already have at least one such editor available on your computer (for example those of you running Windows will have Notepad). This must be a plain text editor and not a word processor as word processors store all sorts of additional information mixed in with what you type (so as to determine how it will look) and that will break your script so that it will not work.

Some of the plain text editors that you can download from the web will provide a friendlier environment in which to write your JavaScript. Those intended for producing content and code for the web will recognise that files where the filename ends in .js are written in JavaScript and will colour code the text for you as you type it in. This will help to make your script easier to read.

While you can copy the formatted script content including the whitespace you can’t copy the colour of the text when you do so and so having an editor that can do it will be more convenient. The text editor we use is CSE HTML Validator Lite which also colour codes your HTML, CSS, and server side code for you as well as having a built in HTML validator.

The other thing you need is a collection of browsers to test your JavaScript in. JavaScript is an interpreted language and the interpreter is built into the browser. Unfortunately different browsers supply slightly different interpreters and so we need to test our code in a number of different browsers before we can be reasonably confident that it will work correctly for most of our visitors (the ones with JavaScript enabled).

The biggest differences in the way the browsers interpret your script is between Internet Explorer and other browsers so as a bare minimum you need one version of IE and some other browser that isn’t IE. Ideally you should test in the latest version of each of the popular browsers – Firefox, Google Chrome, Safari and Opera – as well as multiple versions of Internet Explorer (since not everyone using IE keeps or even can keep their browser completely up to date the way people using other browsers generally do).

As Internet Explorer is built into the Windows operating system you will either need multiple computers or set up a virtual PC environment to be able to test in multiple versions of IE. If this sounds too complicated then simply start out testing in whatever version of IE you have and be prepared to amend your code if someone using a different version tells you it doesn’t work for them.

Each browser with the exception of Firefox and earlier versions of Internet Explorer (IE7 and earlier) have a set of Developer Tools built into the browser which includes a JavaScript debugger that will allow you to step through your code running one statement at a time and seeing what it does. You may not use the debuggers when testing your scripts in the early days but you will make use of the debugger when you start to write really complex scripts later on.

The debugger for Firefox is the Venkman JavaScript Debugger. As the debugger for each browser is basically the same except for where some of the buttons are positioned once you learn how to use one of the debuggers you should be able to use the debugger in any of the browsers.

To use the Example Code

All of the example code on this site is displayed in textareas within the web page. You will find a button under each textarea that you can click to select all of the code within the textarea (provided you have JavaScript enabled – otherwise you’ll need to use some other method of selecting the example code eg. ctrl-a).

You can then copy the code using whichever copy command you prefer (ctrl-c, right click/copy, or alt e c) and paste it into your editor (ctrl-p, right click/paste, or alt e p). Make whatever changes you need to the code so it will work for what you want it to do and then save the file with the appropriate file extension (.htm or .html for HTML, .css for CSS and .js for JavaScript). You can then test if the code works by opening the local file in your browser.

Note that when testing local files in Internet Explorer you will need to give the browser permission to run JavaScript locally. This is because there are commands only recognised by IE that may create major security issues if you allow a script containing them to run locally. As those commands only work in Internet Explorer and do not have equivalents for other browsers they are unsuitable for use in web pages and are therefore not covered on this site.

Copyright and JavaScript

Many of the examples on this site are too small to be covered by copyright and you may use them freely as you wish.

Larger scripts both here and elsewhere on the web are covered by copyright. They will normally contain a comment at the top advising you as to who wrote the script and therefore owns the copyright. The lack of such a notice does not mean that the script is not covered by copyright though. If in doubt then assume that a script is covered by copyright and ask the site owner for permission to use the script.

Where scripts are covered by copyright (whether they contain a notice to that effect or not) you will need the permission of their owner if you wish to use them. With sites actually about JavaScript you are likely to find the conditions specified on the site itself with respect to what scripts you are allowed to copy and what you are allowed to do with them (as this site does).

Sites about other topics which merely use JavaScript are unlikely to grant permission to copy their scripts on their site and so if you wish to copy scripts from one of those sites you should contact the script owner for permission.

Share this article:

Leave a Comment