Skip to main content
InterviewHubPRO
Section Overview
Q461

Question 461 of 536

Part 7: Execution Context, Functional JS & V8 Engine (404 - 463)

86%
JavaScript & V8 Internals (536 Qs)•Part 7: Execution Context, Functional JS & V8 Engine (404 - 463)

What are the examples of built-in higher order functions?

senior LevelCode ExampleMemory Management

There are several built-in higher order functions exists on arrays, strings, DOM and promise methods in javascript. These higher order functions provides significant level of abstraction. The list of functions on these categories are listed below,

  1. arrays: map, filter, reduce, sort, forEach, some etc.
  2. DOM: The DOM method element.addEventListener(type, handler) also accepts the function handler as a second argument.
  3. Strings: replace() method.

Practical Code Example

javascript
// Built-in Higher-Order Functions on Array prototype:
const numbers = [1, 2, 3, 4, 5];

const doubled = numbers.map(x => x * 2);      // [2, 4, 6, 8, 10]
const evens = numbers.filter(x => x % 2 === 0); // [2, 4]
const sum = numbers.reduce((acc, x) => acc + x, 0); // 15