BETAThis is a new service – your feedback will help us to improve it.

Introducing Javascript

So far, we've used HTML to give our webpages content and structure, and we've used CSS give them presentation.

Next, we're going to use Javascript to add functionality and interactivity to those web pages.

A while ago, we used our browser's developer tools to write a simple Javascript program. We're going to revisit that now.

What Javascript is for

Although the web began as a way for scientists and governments to trade written documents, people quickly tried to make the web do more exciting things.

Flash was used in the early days of the web, but Flash made webpages slow and insecure, didn't work well on mobile devices and had poor accessibility.

Javascript was the first true programming language invented for the web. We can use it to build complex, interactive websites that, if done properly, avoid most of the issues with Flash.

Many popular websites, like Twitter, Facebook, BBC iPlayer and Gmail, rely heavily on Javascript.

Compared to HTML and CSS

One of the key advantages Javascript has over simpler languages like HTML and CSS is logic. HTML,CSS and Javascript all serve different function in creating websites

HTML and CSS give a browser a fixed recipe for what to display on the screen. That recipe is the same under all circumstances.

However, we can use Javascript to tell a browser to do things only under certain conditions.

For instance, if a user clicks a button, we could display a menu, show some extra text, or trigger an animation.

Not all those conditions have to be related to user input. We can do things depending on data coming from elsewhere, so we can update a web page in real-time without waiting for the user to reload.

Where Javascript runs

For this module, we'll focus on Javascript running in the browser - where it was originally designed to run.

In later modules, we'll look at other uses of javascript.

Lessons last updated 12th July 2019. You can improve this lesson on Github.
Part of Adding interactivity
  1. Introducing Javascript
  2. Your first Javascript program
  3. Variables
  4. Conditional logic
  5. Affecting the page
  6. Making a menu
  7. Responding to user actions
  8. Keep your Javascript accessible
  9. Get confident with Javascript
  10. Add interactivity to your prototypesP