Skip to main content

JavaScript Arrow Functions — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Arrow Functions lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.

Exercises(5)

  1. 1

    Write an arrow function

    easy10 min

    Write an arrow function that doubles a number. Show it for 25.

  2. 2

    Use an implicit return

    easy10 min

    Write the same doubling function in one line with no braces. Show it for 33.

  3. 3

    Two parameters

    easy10 min

    Write an arrow function that adds two numbers. Show 8 plus 9.

  4. 4

    An arrow as a callback

    easy10 min

    Use an arrow function with map to square each number, then join with commas.

  5. 5

    Return an object

    medium10 min

    Return an object from a one-line arrow function and show its name.

Find the bug(5)

  1. 1

    Fix the missing arrow

    easy8 min

    An arrow function needs the arrow between the parameters and the body.

  2. 2

    Fix the braces without return

    easy8 min

    With braces the function must return explicitly.

  3. 3

    Fix the missing brackets

    easy8 min

    With two parameters the round brackets are required.

  4. 4

    Fix the object read as a body

    easy8 min

    Without round brackets the braces are treated as a function body.

  5. 5

    Fix the arrow used as a method

    easy8 min

    An arrow function has no this, so it cannot see the object.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace