JavaScript exercises
JavaScript exercises for deliberate practice
Practice JavaScript exercises for beginners and intermediate learners covering variables, operators, loops, functions, arrays, objects, promises, async/await, DOM, fetch, JSON, classes, modules, and regex.
Practice JavaScript exercises by topic
Beginner
JavaScript variables exercises
Practice naming values, updating state, and choosing between let and const in small scripts.
- Create variables for a product name, price, and in-stock flag.
- Update a counter after each simulated cart action.
- Rewrite var declarations using let and const.
- JavaScript variables exercises
- let const practice
- beginner JavaScript
Beginner
Operators and comparisons exercises
Build confidence with arithmetic, strict equality, comparison rules, boolean logic, and nullish values.
- Calculate a discounted total from price, quantity, and coupon values.
- Write conditions that distinguish empty strings, zero, null, and undefined.
- Combine access rules with AND, OR, and NOT operators.
- JavaScript operators practice
- comparison exercises
- boolean logic
Beginner
Loops and control flow exercises
Practice if statements, switch branches, while loops, for loops, break, and continue.
- Print only even numbers from a list of scores.
- Convert a numeric status code into a label with switch.
- Stop scanning a list once the first matching item is found.
- JavaScript loops exercises
- if else practice
- control flow
Beginner
Function exercises
Write reusable JavaScript functions with parameters, return values, default values, and arrow syntax.
- Create a formatPrice function that accepts a number and returns a currency string.
- Rewrite a function declaration as an arrow function.
- Use a default parameter for a missing greeting name.
- JavaScript function exercises
- arrow function practice
- return values
Intermediate
Array method exercises
Practice map, filter, reduce, find, includes, some, every, sort, and array copying patterns.
- Filter a product list to show only available items.
- Transform user records into display labels.
- Reduce an order list into a total price.
- JavaScript array exercises
- array methods practice
- map filter reduce
Intermediate
Object exercises
Practice object literals, property access, methods, destructuring, spread, copying, and optional chaining.
- Read nested profile data safely when optional fields are missing.
- Merge default settings with user settings without mutating either object.
- Add a method that returns a formatted summary of an object.
- JavaScript object exercises
- object practice
- destructuring exercise
Intermediate
Promise exercises
Practice promise states, chaining, error handling, Promise.all, Promise.race, and async flow.
- Chain two asynchronous operations and pass the result forward.
- Handle a rejected promise with a recovery value.
- Load several independent resources and combine their results.
- JavaScript promise exercises
- promise practice
- asynchronous JavaScript
Intermediate
Async/await exercises
Rewrite promise chains with async functions and await while preserving error handling and return values.
- Convert a then/catch chain into an async function.
- Use try/catch around awaited work.
- Run independent awaited tasks in parallel instead of one after another.
- async await exercises
- JavaScript async practice
- await promise
Intermediate
DOM exercises
Practice selecting elements, updating text, changing classes, creating nodes, and handling user events.
- Toggle a completed class when a task item is clicked.
- Create a new list item from an input value.
- Use event delegation for buttons inside a list.
- JavaScript DOM exercises
- DOM practice
- event listener exercises
Intermediate
Fetch and JSON exercises
Practice API request flow, JSON parsing, response checks, loading states, aborting, and error messages.
- Show a loading state while a request is in progress.
- Parse JSON data and render a list of result names.
- Display a useful error message when a request fails.
- JavaScript fetch exercises
- JSON practice
- API request exercise
Intermediate
Class exercises
Practice constructor methods, instance methods, inheritance, static members, and private fields.
- Create a User class with a formatted display name method.
- Extend a base class with a specialized subclass.
- Use a private field to protect internal state.
- JavaScript class exercises
- class practice
- inheritance exercise
Intermediate
Module exercises
Practice named exports, default exports, import paths, module boundaries, and reusable utilities.
- Move a formatting helper into a separate module.
- Export multiple utilities from one file and import only one of them.
- Replace a default export with named exports.
- JavaScript module exercises
- import export practice
- ES modules
Intermediate
Regular expression exercises
Practice matching, testing, extracting, replacing, and validating strings with JavaScript RegExp.
- Validate a simple username format.
- Extract all numbers from a text string.
- Normalize repeated whitespace into a single space.
- JavaScript regex exercises
- regular expression practice
- RegExp challenges