TExcelTAD
Home › JavaScript › JS Introduction

JavaScript Introduction

JavaScript is the programming language of the web. Every modern browser — Chrome, Firefox, Safari, Edge — contains a JavaScript engine, so the code you write runs for anyone who opens your page, with nothing to install. HTML describes what is on a page, CSS describes how it looks, and JavaScript describes how it behaves.

What can JavaScript do?

  • React to clicks, key presses and form input
  • Change the text, images and styles of a page without reloading it
  • Fetch data from servers and show it live (weather, chat messages, search suggestions)
  • Draw games and charts, play audio and video
  • Run outside the browser too: servers with Node.js, desktop apps, mobile apps and command-line tools

The web trio

Language Role Example
HTML Structure and content <button>Buy</button>
CSS Presentation button { color: white; }
JavaScript Behaviour "when the button is clicked, add the item to the cart"

Note: Despite the name, JavaScript has nothing to do with Java. The name was a marketing decision in 1995. The official standard is called ECMAScript (ES), and new versions are released every year — ES2015 (also called ES6) was the big modernisation that introduced let, const, arrow functions, classes and modules.

Your first program

The quickest way to see what a JavaScript program does is console.log(), which writes a value to the console. Press ▶ Run, then change the text and run it again.

js · try it yourself
console.log("Hello, World!");
Hello, World!

You can log numbers, calculations and several values at once — separated by commas, they are printed with a space in between:

js · try it yourself
console.log(2 + 3);
console.log("The answer is", 6 * 7);
console.log("JavaScript", "runs", "everywhere");
5
The answer is 42
JavaScript runs everywhere

Tip: In every playground on ExcelTAD you can edit the code and press Ctrl+Enter to run it. Every browser also has a console of its own: press F12 (or Cmd+Option+J on a Mac) and choose the Console tab to try JavaScript on any page.

JavaScript in a web page

Inside a web page, JavaScript lives in a <script> element. This example changes the text of a heading when you click the button:

html · try it yourself
<h2 id="greeting">Hello!</h2>
<button onclick="document.getElementById('greeting').textContent = 'You clicked me!'">
  Click me
</button>

Don't worry about the details yet — selecting elements and handling events each get their own chapters. The point is that a few characters of JavaScript turn a static page into an interactive one.

A slightly bigger taste

Here is a program that uses a variable, a loop and a template string. Read it top to bottom; you will learn every piece of it in the coming chapters.

js · try it yourself
const language = "JavaScript";
for (let i = 1; i <= 3; i++) {
  console.log(`${i}. I am learning ${language}`);
}
1. I am learning JavaScript
2. I am learning JavaScript
3. I am learning JavaScript

How this course is organised

  1. JS Tutorial — the core language: variables, types, functions, objects, arrays, loops, classes and modules.
  2. JS Async — callbacks, promises and async/await for work that takes time.
  3. JS Advanced — closures, generators, prototypes and property accessors.
  4. HTML DOM — reading and changing a live web page.
  5. Browser APIs — timers, storage and the Fetch API.
  6. Practice — exercises and a small project that ties it all together.

Test yourself

Which of the three web languages controls a page's behaviour?

  1. HTML
  2. CSS
  3. JavaScript
  4. SVG

What does console.log("a", "b") print?

  1. ab
  2. a b
  3. a,b
  4. ["a", "b"]

What is the official name of the JavaScript standard?

  1. JScript
  2. ECMAScript
  3. Java
  4. TypeScript