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 elementsA part of the content of a web page. or attributesExtra information added to an element., 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 branchingUsing different actions for different cases. and iterationThe process of repeating, or one repetition in that process.. It is a loosely-typedA programming language that allows a variable to be used for different types of data. language (variablesThe name used to refer to some data and the address (location) where it is stored; this is allowed to change. are not assigned to specific data typesA type of data, such as a number or a string.), and is object-oriented. In fact, even data types like numbers can be treated as objectsA "bundle" of values., 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 nameThe characters used in a tag for a particular element. 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 elementAn HTML element that gives information about the page, tag name <code>head</code>. or body elementAn HTML element that contains all the content of the page, tag name <code>body</code>..

When placed in a separate file, the name of the file is the value of a source attributeAn attribute used to specify the source from which a file can be obtained. (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.