Skip to content

Instantly share code, notes, and snippets.

@samarpanda
Created March 23, 2015 08:27
Show Gist options
  • Save samarpanda/3b26920e4031b876327d to your computer and use it in GitHub Desktop.
Save samarpanda/3b26920e4031b876327d to your computer and use it in GitHub Desktop.
JS has 1st Class Functions
/**
* 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