Arrow Functions, online
Six activities your students do on their own devices. See who's finished, and their scores.
Arrow Functions in one minute
What students need to know
The arrow => is exactly what makes this shorthand possible. Empty parentheses are still needed with zero parameters.
The arrow => comes right after the parameters. JavaScript always uses =>, never ->.
Mistakes students make
- Arrow functions use =>, not ->, between parameters and body.
- Arrow functions don't use the 'function' keyword - remove it.
- Arrow functions with no parameters need empty parentheses: ().
- Multiple parameters need a comma between them: (a, b).
What students will learn in this module
Every question in Module 42
Quick questions
- Does => separate the parameters from the function body in an arrow function?AYesBNo
- Is -> used instead of => in JavaScript arrow functions?ANoBYes
- Do arrow functions with no parameters still need empty parentheses?ANoBYes
- Does an arrow function need the 'function' keyword?AYesBNo
- Can an arrow function with a single parameter omit the parentheses?AYesBNo
Key terms
Students type the meaning of:
=>
Match the pairs
(a, b) => a + bMatch it to what it doesx => x * 2Match it to what it doesA shorter way of writing a function expressionMatch it to what it doesRequired even when an arrow function has no parametersMatch it to what it doeslet f = (a, b) -> a + b;Match it to what it doeslet g = function (x) => x;Match it to what it doesFill in the blanks
let add = (a, b) __ {Hint: Type the arrow that separates the parameters from the function body.
let double = x __ x * 2;
Hint: Type the arrow that separates the parameter from the function body.
let greet = _) => "Hi";
Hint: Type the opening parenthesis for a no-parameter arrow function.
let square = (n) __ n * n;
Hint: Type the arrow that separates the parameters from the function body.
let multiply = (x, y) __ x * y;
Hint: Type the arrow that separates the parameters from the function body.
Spot the error
Question 1
Alet f = (a, b) -> a + b;Bconsole.log(f(2, 3));Clet g = (x) => x * 2;
Question 2
Alet h = (x) => x + 1;Bconsole.log(h(5));Clet i = function (x) => x;
Question 3
Alet j = => 5;Bconsole.log(j());Clet k = () => 10;
Question 4
Aconsole.log(m(1, 2));Blet m = (a b) => a + b;Clet n = (x) => x * x;
Question 5
Alet p = (x) => x - 1;Bconsole.log(p(5));Clet q = (y) => y + 1;Dlet r = (z) -> z * 2;
