Introduction to JavaScript

This tutorial is part of a web programming course for people who have no programming experience.

Each of the programming languages that we are covering in this course has a specific purpose in a web page:

  • HTML allows you to structure the content.
  • CSS controls the visual presentation.
  • JavaScript controls the behavior (makes your pages 'interactive' for the user).

Here are just some of the things you can do when you are incorporating JavaScript into your web pages.

Use JavaScript to Respond to Events (Event Handling)

If you want something to happen when a visitor does something (for example, presses a button), you can use JavaScript code to make something happen. This is known as event handling, and it allows visitors to interact with your pages.

Use JavaScript to Validate User Input

We often need to collect data from the people who visit a website, and we saw how to do that when we went over HTML forms. We need to make sure that the data entered is correct. For example, if you ask a user to enter a number, such as their age, we need to notifiy them if they enter somethin other than a valid number. We can write JavaScript code that will respond to this invalid user input and let people know that they need to correct it.


JavaScript can be used to animate a page. You can actually make complex 3-D video games in JavaScript.

Fetch Data From a Web Server

You can use JavaScript to fetch data from various servers on the internet. This how many web pages are created these days. When you think abou all the information that is available on the internet, you begin to understand the endless possibilities for the web apps that you can build.

Control Elements in the HTML

You can write JavaScript to change elements in the HTML code. You can alter the content inside and element, and even control the CSS styles that are applied to an element. You can also add and remove elements. In the video above, you saw how JavaScript can be used to fetch data from a web server, then display it to the user by adding a list to the body of the HTML document.

NEXT LESSON: Variables and Data Types