Skip to the content

Arrow functions

JavaScript · Unit 4: Functions

An arrow function is another way of writing a function: it's stored in a variable and carries =>.

With no braces, it hands back the result without you writing return.

const double = (n) => n * 2;

console.log(double(5));

Prints

10

The rest of the explanation is in the lesson, which is part of the full plan.

Exercises in this lesson

You do them in the app, which checks them on the spot and explains why.

  1. 1. Predict the output

    What does this code print?

  2. 2. Complete the code

    Fill in the blank so half(10) hands back 5.

  3. 3. Predict the output

    What does this code print?

  4. 4. Find the bug

    This program should print the area of 4 by 3, that is 12. Which line has the error?

  5. 5. Multiple choice

    What does this line do?

  6. 6. Complete the code

    Fill in the blank so subtract(10, 4) hands back 6.

  7. 7. Predict the output

    What does this code print?

  8. 8. Find the bug

    This program should print the double of 10. Which line has the error?

  9. 9. Put the lines in order

    Put in order the program that adds a price of 70 and 5 for shipping.

  10. 10. Find the case that fails

    change(paid, price) should hand back the change, and 0 when the payment isn't enough. Which call makes it fail?

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →