Higher-Order Function in JavaScript
Level 3127 keystrokes
Higher-order functions return other functions, enabling function factories.
JavaScript code
// Define a function that returns another function// This is called a higher-order function1function createMultiplier(factor) { // Return an arrow function that multiplies by factor // The returned function is a closure: it remembers factor2 return (num) => num * factor;3}// Create a function that doubles numbers4const double = createMultiplier(2);// Call the created function: 5 * 2 = 105console.log(double(5));Output
10
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=× 2.× 1{× 1}× 1*× 1>× 1