Created
March 23, 2015 08:27
-
-
Save samarpanda/3b26920e4031b876327d to your computer and use it in GitHub Desktop.
JS has 1st Class Functions
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
/** | |
* Why we call javascript as a first class functions | |
*/ | |
// Create a function | |
var square = function(x){ | |
return x*x; | |
}; | |
// Return a function | |
var mult = function(f1, f2){ | |
return function(n){ | |
return f1(n) * f2(n); | |
} | |
}; | |
//Arguments can be passed as functions. | |
var bigF = mult(square, square); | |
//Default and other languages supports i.e calling a function | |
var value = bigF(2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment