JavaScript examples

The JavaScript hub collects practical examples written in the plain language that browsers execute today. It covers listening for and delegating user events, observing when elements enter the viewport, sending fetch requests and reading their responses, validating form input before submission, reshaping arrays and records in memory, and driving component state from vanilla code. Each entry states the runtime it assumes, shows a short accurate answer before the explanation, and links a labelled code block you can copy. Use the task groups to compare approaches at the same difficulty level, then follow the relationship links to move from a single call to a complete, maintainable pattern for your own page.

12 published examples in 6 taskgroups. Hub pages list every Example in exactly one task group.

Fetch API data

2 examples

Send a request, await the response, and handle status, timeout, and cancellation behaviour.

Handle DOM events

3 examples

Attach, configure, delegate, and remove browser event listeners correctly.

Manage React state

1 example

Declare, derive, update, and share component state inside the React render model.

Observe element visibility

2 examples

React to intersection, viewport entry, or document visibility changes.

Transform data

1 example

Reshape collections and records in memory into the structure the next step needs.

  • Group array items by a computed key

    Build a plain object whose keys come from each record, so lookups stop scanning the list and grouping stops needing a second pass.

    JavaScriptbeginner

Validate form input

3 examples

Decide whether entered data is acceptable and report the result to the person filling the form.

Adjacent navigation