Skip to content

Instantly share code, notes, and snippets.

@suhailgupta03
Created August 16, 2023 14:47
Show Gist options
  • Save suhailgupta03/5e73ce9071043bb41cf8aa7f6181f91b to your computer and use it in GitHub Desktop.
Save suhailgupta03/5e73ce9071043bb41cf8aa7f6181f91b to your computer and use it in GitHub Desktop.
function sum(a, b) {
return a + b;
}
function printSum() {
return sum;
} // printSum is now a higher-order function
// because it returns a function as a result
// printSum() will return a function sum and then you
// can make call from the returned value
// var s = printSum()
// s(1,2)
function printSumVersion2(arg) {
// arg is now equivalent to sum
var r = arg(5, 10);
console.log(r);
} // printSumVersion2 is now a higher-order function
// because it takes a function as an argument
printSumVersion2(sum)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment