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).

Discover other journeys with this module

What students will learn in this module

Every question in Module 42

Quick questions

  1. Does => separate the parameters from the function body in an arrow function?AYesBNo
  2. Is -> used instead of => in JavaScript arrow functions?ANoBYes
  3. Do arrow functions with no parameters still need empty parentheses?ANoBYes
  4. Does an arrow function need the 'function' keyword?AYesBNo
  5. 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 does
x => x * 2Match it to what it does
A shorter way of writing a function expressionMatch it to what it does
Required even when an arrow function has no parametersMatch it to what it does
let f = (a, b) -> a + b;Match it to what it does
let g = function (x) => x;Match it to what it does

Fill in the blanks

  1. let add = (a, b) __ {

    Hint: Type the arrow that separates the parameters from the function body.

  2. let double = x __ x * 2;

    Hint: Type the arrow that separates the parameter from the function body.

  3. let greet = _) => "Hi";

    Hint: Type the opening parenthesis for a no-parameter arrow function.

  4. let square = (n) __ n * n;

    Hint: Type the arrow that separates the parameters from the function body.

  5. 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;