Skip to content
Science, Maths & Technology

Getting Started With Programming Using JavaScript

Updated Monday, 22nd June 2015

Start learning programming by using JavaScript, a powerful web-based programming language.

This page was published over five years ago. Please be aware that due to the passage of time, the information provided on this page may be out of date or otherwise inaccurate, and any views or opinions expressed may no longer be relevant. Some technical elements such as audio-visual and interactive media may no longer work. For more detail, see our Archive and Deletion Policy


Keyboard Copyrighted  image Icon Copyright: Dreamstime In this collection of articles we aim to introduce you to:

  • writing code to read in data from a user, perform some simple processing and display the result;
  • programming for sequence, selection and repetition in a high-level language, specifically:
    • how to achieve selective execution of sections of program code as a result of the evaluation of some condition;
    • how to achieve repeated execution of a section of program code, either while a particular condition is true or for a specified number of times.

You will be using a widely available high-level programming language called JavaScript. We provide you with a small set of programs to run, alter and experiment with, and you will also be writing your own small programs from scratch.

JavaScript is not the same as Java. Although JavaScript code looks a bit like Java, and the two languages are often used together to produce web-based applications, they are otherwise unrelated.

Recommended software


JavaScript programs are normally run in a web browser.

Although any standard browser will do, for our purposes we recommend Mozilla Firefox.

Download Mozilla Firefox

Text editor

A browser will run a JavaScript program but how does a program get written in the first place, and how can you change it? To do this a text editor is needed, which lets you write program code, modify it, and save the result in a file that can be read by a browser.

The built-in text editor that comes with Windows is Notepad. This can be used for writing JavaScript programs but it is quite basic and we believe you will find it easier and more convenient to use an editor with additional features. The one we recommend is Notepad++, which is a free source editor.

If you have not done so already, you should install both Firefox and Notepad++ before going on. If you are interested in learning in-depth about how to use Notepad++, you can visit the Notepad++ wiki.

Download Notepad++

If you are a Mac user, the text editor that comes with Mac OS X is TextEdit. Alternatively, a more powerful text editor is TextWrangler which can be downloaded for free, from here:

Speaking the Language

In programming, we use a formal language to communicate with a machine. If you don’t follow the rules of the language, known as its syntax, exactly, your program will not run or will not run as you expect. It can be a very frustrating experience to have to look for mistakes – usually called 'bugs'.

Please don’t be put off if you do make mistakes. Many people find that the process of making mistakes, and then working out why they are mistakes and correcting them, forms a very valuable – and even enjoyable – learning experience. You might find it helpful to keep a record of any mistake you make, and how it is corrected, for your future reference. You can think of the syntax of a language as its grammar. Programming languages also have vocabulary and meaning just like natural (spoken) languages.

As well as syntax, programming languages have reserved words, sometimes called keywords, i.e. words which have a special meaning in the particular programming language (you can think of the reserved words as constituting part of the vocabulary, or dictionary, for that language). Many programming languages use reserved words which look like English (such as while, for and if). But beware: the meaning of these words in the programming language might not exactly match their English equivalents. We shall explain the meaning (semantics) of these words in the programming language as we meet them.

We should note at this point that JavaScript is case sensitive. This means that, for example, the JavaScript interpreter treats If, IF and if as being different. All the reserved words in JavaScript are lower case, i.e. they have no capital letters.

We have provided working code for all the activities you'll be attempting, which, as a last resort, you may look at and run yourself. However, learning to program is a bit like learning to ride a bicycle: your learning will be extremely limited if you simply observe what other people have done. In order to really understand how to program, you have to write your own programs (albeit with a little help from us).

It can be an intensely satisfying, rewarding and creative experience to write a program which behaves in exactly the way you wish it to. It is now time to introduce you to this experience.

In this section, you will be writing some simple programs, which will enable you (or some other user) to input data via the mouse and keyboard, perform some simple processing on the data and then display the results of the processing.

Specifically, this section aims to:

  • describe how to write a program to display information;
  • discuss the concept of a programming variable;
  • discuss the concept of data types, with reference to numbers and strings, together with some operations on them (arithmetical operations on numbers; concatenation of strings);
  • describe how to use a dialogue box to obtain input into a program;
  • discuss how to transform input data into numbers, where appropriate.

To get started, pick an article from the menu below. We recommend starting with 'Your First Program'.

An Introduction to programming using JavaScript




Related content (tags)

Copyright information

For further information, take a look at our frequently asked questions which may give you the support you need.

Have a question?