When you call a map, you pass in a built-in function or an existing function.
// The following would return [2,3,4] map(function(item) { return item + 1}, [1,2,3]); function double(item) {return item*2} map(double, [1,2,3]) // returns [2,4,6] // Your example, Math.round map(Math.round, [0.01, 2, 9.89, Math.PI]) // returns [0,2,10,3]
Another way of saying that a function can be passed to another function is like any other argument. It is on the same lines that a function, like any other variable, can be passed or returned from a function
function createAdder(toAdd) { return function (num) { return num + toAdd; } } var add5 = createAdder(5); add5(2);
source share