Introduction

JavaScript is the programming language that makes web pages interactive.

Syntaxconsole.log(value);

JavaScript is the world's most popular programming language. It is the language of the web, running in every browser as well as on servers, phones and beyond.

What can JavaScript do?

  • Change the content and style of a web page.
  • React to clicks, typing and other user actions.
  • Store and process data, talk to servers, and much more.

In these lessons every example is real, runnable code. Click Try it and the output of console.log() appears in the panel below the editor.

Example

Try it yourself
Loading editor…
Press Run to execute the code.

When to use it

  • Validate a form field in real time before the user submits it to the server.
  • Show a live countdown timer that updates every second on an event landing page.
  • Fetch product data from a REST API and render it dynamically without reloading the page.

More examples

Alert on button click

Attaches a click listener to a button and shows a browser alert when it fires.

Example · js
document.getElementById("btn").addEventListener("click", function () {
  alert("Hello from JavaScript!");
});

Change element text dynamically

Selects a DOM element by id and replaces its text content at runtime.

Example · js
const heading = document.getElementById("title");
heading.textContent = "Page updated by JavaScript";

Fetch and display API data

Uses the Fetch API to retrieve JSON from a server and injects the first product name into the DOM.

Example · js
fetch("https://api.example.com/products")
  .then(res => res.json())
  .then(data => {
    document.getElementById("list").textContent = data[0].name;
  });

Discussion

  • Be the first to comment on this lesson.
Introduction — JavaScript | SoundsCode