M. Kodirov

STAGE 01 / LESSON 06

JavaScript: values, functions and events

JavaScript adds behavior to a page and transforms data for the interface.

THE IDEA

Understand it.

Variables hold values, objects group related data, and functions describe reusable behavior. Prefer const when a binding will not be reassigned; it does not make the contents of an object immutable.

The browser exposes the DOM, which represents the document. Event listeners let code respond to actions such as a button click. Treat user-provided text as text, not trusted HTML.

SEE IT IN CONTEXT

Update a task label

const task = { title: "Review API", done: false };
const button = document.querySelector("button");

button?.addEventListener("click", () => {
  task.done = true;
  button.textContent = "Completed";
});

The handler runs on a click. textContent writes text without interpreting it as HTML.

LEARN FROM REAL WEBSITES

See it in the real world.

These simplified structures come from public sources. Company systems change, and the sources may describe only one project or an earlier design.

Spotify

Tutorial checked November 2026

A small profile application

Spotify's public tutorial builds a web app that requests a user's profile and displays information in a page.

  1. User action
  2. JavaScript application
  3. Spotify API
  4. Profile on page

What to learn: Functions, asynchronous requests and DOM updates turn received data into a visible interface. This is an instructional example.

Read the source: Spotify profile web app tutorial

GitHub

Public code checked November 2026

A button responds to interaction

The open-source Primer Brand button includes React state and handlers for pointer and focus interactions.

  1. Pointer or focus event
  2. Button handler
  3. Component state

What to learn: An event can run code and change UI state. The linked component is an example, not the implementation of every GitHub button.

Read the source: Primer Brand button source

TRY IT YOURSELF

Practice.

What happens if the page has no button? Why does the example use optional chaining?

Show one possible answer

querySelector returns null. Optional chaining skips registering the listener instead of trying to call a method on null.

GO DEEPER

Official references.