Created
August 16, 2023 14:47
-
-
Save suhailgupta03/5e73ce9071043bb41cf8aa7f6181f91b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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