Arrow functions
JavaScript · Unit 4: Functions
- Full plan
- JavaScript
- 10 exercises
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. Predict the output
What does this code print?
2. Complete the code
Fill in the blank so
half(10)hands back 5.3. Predict the output
What does this code print?
4. Find the bug
This program should print the area of 4 by 3, that is 12. Which line has the error?
5. Multiple choice
What does this line do?
6. Complete the code
Fill in the blank so
subtract(10, 4)hands back 6.7. Predict the output
What does this code print?
8. Find the bug
This program should print the double of 10. Which line has the error?
9. Put the lines in order
Put in order the program that adds a price of 70 and 5 for shipping.
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?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.