JavaScript examples
JavaScript examples for practical learning
Practice JavaScript examples for variables, functions, arrays, objects, promises, async/await, DOM, events, fetch, JSON, and regular expressions.
Practice JavaScript examples by topic
JavaScript variables example
Start with naming values, updating data, and choosing between let and const in small scripts.
- JavaScript variables
- let const example
- declare variable
JavaScript function example
Practice defining reusable behavior with parameters, return values, declarations, expressions, and arrow functions.
- JavaScript functions
- function example
- arrow function
JavaScript array example
Use arrays and array methods to store ordered values, transform lists, filter data, and reduce results.
- JavaScript arrays
- array methods
- map filter reduce
JavaScript object example
Model structured data with objects, properties, methods, this, constructors, and copying behavior.
- JavaScript objects
- object methods
- this JavaScript
JavaScript promise example
Learn how promises represent asynchronous results and how chains pass values through then handlers.
- JavaScript promises
- promise example
- promise chaining
Async/await example
Rewrite promise-based code with async functions and await so asynchronous flow reads more clearly.
- async await example
- JavaScript async
- await promise
DOM example
Read and change page nodes, attributes, classes, styles, and document structure with browser APIs.
- JavaScript DOM
- DOM example
- querySelector
JavaScript event example
Handle browser events with bubbling, capturing, delegation, form input, keyboard, pointer, and mouse events.
- JavaScript events
- event delegation
- browser events
Fetch API example
Use fetch to make network requests, handle responses, work with JSON, abort requests, and track progress.
- JavaScript fetch
- Fetch API example
- network request
JSON example
Convert JavaScript values to JSON strings and parse JSON data back into objects for APIs and storage.
- JSON JavaScript
- JSON parse
- JSON stringify
Regular expression example
Match, search, validate, and replace text with JavaScript RegExp patterns and string methods.
- JavaScript regex
- RegExp example
- regular expression
Class example
Create reusable object blueprints with class syntax, inheritance, static members, and private fields.
- JavaScript class
- class example
- class inheritance