Higher order functions and closures example in Javascript

1 · Adrian Matei · Aug. 11, 2021, 10:28 a.m.
First with “normal” functions: //closures and higher order function function salute(salutation) { return function(firstName) { return function(lastName) { console.log(`hi ${salutation} ${firstName} ${lastName}`) } } } salute('Mr.')('John')('Wick') //output hi Mr. John Wick The shorter variant with arrow functions: const saluteArrowFunction = (salutation) => (firstName) => (lastName) => console.log(`hi ${salutation} ${firstName} ${lastName}`); saluteArrowFunction ('Mr.')('J...