Arrow Functions

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

This Arrow Functions worksheet is part of the JavaScript Coding without HTML and CSS journey. Print it as a booklet?

Arrow Functions

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Does => separate the parameters from the function body in an arrow function?
A Yes
B No
2. Is -> used instead of => in JavaScript arrow functions?
A No
B Yes
3. Do arrow functions with no parameters still need empty parentheses?
A No
B Yes
4. Does an arrow function need the 'function' keyword?
A Yes
B No
5. Can an arrow function with a single parameter omit the parentheses?
A Yes
B No

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1(a, b) => a + b ADoubles x using a single-parameter arrow function
2x => x * 2 BAdds a and b together using an arrow function
3A shorter way of writing a function expression CWrong - use =>, not ->, between parameters and body
4Required even when an arrow function has no parameters DWrong - arrow functions don't use the 'function' keyword
5let f = (a, b) -> a + b; E=>
6let g = function (x) => x; F()

Definitions

=>

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
let add = (a, b) __ {
2.
let double = x __ x * 2;
3.
let greet = _) => "Hi";
4.
let square = (n) __ n * n;
5.
let multiply = (x, y) __ x * y;

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A let f = (a, b) -> a + b;
B console.log(f(2, 3));
C let g = (x) => x * 2;
Question 2
A let h = (x) => x + 1;
B console.log(h(5));
C let i = function (x) => x;
Question 3
A let j = => 5;
B console.log(j());
C let k = () => 10;
Question 4
A console.log(m(1, 2));
B let m = (a b) => a + b;
C let n = (x) => x * x;
Question 5
A let p = (x) => x - 1;
B console.log(p(5));
C let q = (y) => y + 1;
D let r = (z) -> z * 2;

Answer Key

Arrow Functions
Section A: Quick Questions
Q1
A — Yes
Q2
A — No
Q3
B — Yes
Q4
B — No
Q5
A — Yes
Section B: Match the Pairs
Q1
(a, b) => a + b → Adds a and b together using an arrow function
Q2
x => x * 2 → Doubles x using a single-parameter arrow function
Q3
A shorter way of writing a function expression → =>
Q4
Required even when an arrow function has no parameters → ()
Q5
let f = (a, b) -> a + b; → Wrong - use =>, not ->, between parameters and body
Q6
let g = function (x) => x; → Wrong - arrow functions don't use the 'function' keyword
Section C: Definitions
Q1
=> — A shorter syntax for writing a function, placed between the parameters and the function body.
Section D: Fill in the Blanks
Q1
let add = (a, b) => {
Q2
let double = x => x * 2;
Q3
let greet = () => "Hi";
Q4
let square = (n) => n * n;
Q5
let multiply = (x, y) => x * y;
Section E: Spot the Error
Q1
A — Arrow functions use =>, not ->, between parameters and body.
Q2
C — Arrow functions don't use the 'function' keyword - remove it.
Q3
A — Arrow functions with no parameters need empty parentheses: ().
Q4
B — Multiple parameters need a comma between them: (a, b).
Q5
D — Arrow functions use =>, not ->, between parameters and body.