JavaScript overview

The language JavaScript is designed specifically for manipulating web pages, which means that the instructions you write are instructions to a web browser on how to manipulate a page. Changes to the page, such as the modification, addition, or deletion of elements or attributes, can be triggered by events such as clicks or movements of the cursor.

Why are some terms underlined with dots?

  • Any term that is underlined with dots is listed in the glossary, accessible from the Help page.
  • To see the definition of an underlined term, put your cursor over the term.
  • To get to the Help page, click on the word Help at the top right corner of any page.

General-purpose features

JavaScript has many of the same general-purpose features as other languages, such as branching and iteration. It is a loosely-typed language (variables are not assigned to specific data types), and is object-oriented. In fact, even data types like numbers can be treated as objects, but we'll avoid doing so. (If you are not familiar with these terms, this might be an indication that you should obtain some more background before continuing. The terms will be defined later, when these concepts are treated in more detail.)

Web features

There are also features suited to web pages, such as ways to respond to user actions (for example, clicks and cursor movements) and a way to access and modify parts of a web page (the Document Object Model). Other useful features include powerful ways to search and change text (regular expressions) and built-in support for storing and changing dates.

Adding JavaScript to a document

A JavaScript program, or script, can be placed in a script element (tag name script) or in a separate file (without script tags), with the latter being preferable when possible, as it helps to separate action from content and style. Later, we will discuss in greater detail the implications of placing a script in the head element or body element.

When placed in a separate file, the name of the file is the value of a source attribute (src) of a script element with no content, such as in the following head element:

<head>
  <meta charset="utf-8">
  <title>Example using a script</title>
  <link rel="stylesheet" href="mystyle.css">
  <script src="code.js"><\script>
</head>

Why do some terms appear in burgundy bold letters?

The styling is used to indicate that the term is being introduced for the first time, and can be found in the glossary.

Some terms in the glossary are part of the background material in HTML, CSS, or programming. Since they are not being introduced in this course, they do not appear in burgundy bold letters.