Arrow Function in JavaScript

Level 378 keystrokes

This defines an arrow function that adds two numbers and calls it twice.

JavaScript code

// Arrow function with the parameters (a, b)
// The expression after => (a + b) is returned automatically
1const add = (a, b) => a + b;
// Call with 3 and 5, returns 8
2console.log(add(3, 5));
// Call with 10 and 20, returns 30
3console.log(add(10, 20));

Output

8
30
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • (× 5
  • )× 5
  • ,× 3
  • ;× 3
  • .× 2
  • =× 2
  • +× 1
  • >× 1

More JavaScript examples at level 3

← JavaScript typing practice