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

  1. Beginner

    JavaScript variables exercises

    Practice naming values, updating state, and choosing between let and const in small scripts.

    1. Create variables for a product name, price, and in-stock flag.
    2. Update a counter after each simulated cart action.
    3. Rewrite var declarations using let and const.
    • JavaScript variables exercises
    • let const practice
    • beginner JavaScript
    Study Variables
  2. Beginner

    Operators and comparisons exercises

    Build confidence with arithmetic, strict equality, comparison rules, boolean logic, and nullish values.

    1. Calculate a discounted total from price, quantity, and coupon values.
    2. Write conditions that distinguish empty strings, zero, null, and undefined.
    3. Combine access rules with AND, OR, and NOT operators.
    • JavaScript operators practice
    • comparison exercises
    • boolean logic
    Study Comparisons
  3. Beginner

    Loops and control flow exercises

    Practice if statements, switch branches, while loops, for loops, break, and continue.

    1. Print only even numbers from a list of scores.
    2. Convert a numeric status code into a label with switch.
    3. Stop scanning a list once the first matching item is found.
    • JavaScript loops exercises
    • if else practice
    • control flow
    Study Loops: while and for
  4. Beginner

    Function exercises

    Write reusable JavaScript functions with parameters, return values, default values, and arrow syntax.

    1. Create a formatPrice function that accepts a number and returns a currency string.
    2. Rewrite a function declaration as an arrow function.
    3. Use a default parameter for a missing greeting name.
    • JavaScript function exercises
    • arrow function practice
    • return values
    Study Functions
  5. Intermediate

    Array method exercises

    Practice map, filter, reduce, find, includes, some, every, sort, and array copying patterns.

    1. Filter a product list to show only available items.
    2. Transform user records into display labels.
    3. Reduce an order list into a total price.
    • JavaScript array exercises
    • array methods practice
    • map filter reduce
    Study Array methods
  6. Intermediate

    Object exercises

    Practice object literals, property access, methods, destructuring, spread, copying, and optional chaining.

    1. Read nested profile data safely when optional fields are missing.
    2. Merge default settings with user settings without mutating either object.
    3. Add a method that returns a formatted summary of an object.
    • JavaScript object exercises
    • object practice
    • destructuring exercise
    Study Objects
  7. Intermediate

    Promise exercises

    Practice promise states, chaining, error handling, Promise.all, Promise.race, and async flow.

    1. Chain two asynchronous operations and pass the result forward.
    2. Handle a rejected promise with a recovery value.
    3. Load several independent resources and combine their results.
    • JavaScript promise exercises
    • promise practice
    • asynchronous JavaScript
    Study Promise
  8. Intermediate

    Async/await exercises

    Rewrite promise chains with async functions and await while preserving error handling and return values.

    1. Convert a then/catch chain into an async function.
    2. Use try/catch around awaited work.
    3. Run independent awaited tasks in parallel instead of one after another.
    • async await exercises
    • JavaScript async practice
    • await promise
    Study Async/await
  9. Intermediate

    DOM exercises

    Practice selecting elements, updating text, changing classes, creating nodes, and handling user events.

    1. Toggle a completed class when a task item is clicked.
    2. Create a new list item from an input value.
    3. Use event delegation for buttons inside a list.
    • JavaScript DOM exercises
    • DOM practice
    • event listener exercises
    Study Event delegation
  10. Intermediate

    Fetch and JSON exercises

    Practice API request flow, JSON parsing, response checks, loading states, aborting, and error messages.

    1. Show a loading state while a request is in progress.
    2. Parse JSON data and render a list of result names.
    3. Display a useful error message when a request fails.
    • JavaScript fetch exercises
    • JSON practice
    • API request exercise
    Study Fetch
  11. Intermediate

    Class exercises

    Practice constructor methods, instance methods, inheritance, static members, and private fields.

    1. Create a User class with a formatted display name method.
    2. Extend a base class with a specialized subclass.
    3. Use a private field to protect internal state.
    • JavaScript class exercises
    • class practice
    • inheritance exercise
    Study Class basic syntax
  12. Intermediate

    Module exercises

    Practice named exports, default exports, import paths, module boundaries, and reusable utilities.

    1. Move a formatting helper into a separate module.
    2. Export multiple utilities from one file and import only one of them.
    3. Replace a default export with named exports.
    • JavaScript module exercises
    • import export practice
    • ES modules
    Study Modules, introduction
  13. Intermediate

    Regular expression exercises

    Practice matching, testing, extracting, replacing, and validating strings with JavaScript RegExp.

    1. Validate a simple username format.
    2. Extract all numbers from a text string.
    3. Normalize repeated whitespace into a single space.
    • JavaScript regex exercises
    • regular expression practice
    • RegExp challenges
    Study Patterns and flags