Skip to content
This repository has been archived by the owner on Oct 20, 2021. It is now read-only.

Latest commit

 

History

History
executable file
·
17 lines (11 loc) · 602 Bytes

ho-functions.md

File metadata and controls

executable file
·
17 lines (11 loc) · 602 Bytes

Higher-order functions

JavaScript has something unique. Instead of data types (values) such as strings, numbers etc. Functions are 'values' themselves. This makes it possible to assign them to another variable, or use in other functions. You call the latter 'higher order functions'. You use them for the composition of your code.

Map

map is probably the best higher-order function to demonstrate.

const num= [1, 2, 3, 4, 5];
const newNum= num.map(i => i * 2); // [2, 4, 6, 8, 10]

console.log(num)
console.log(newNum)

map return a new array with the modified numbers.