First-Class Functions
Functions in JavaScript are first-class objects, which means they can be treated like any other object: they can be assigned to a variable, passed as values to other functions, returned as the value from another function. Basically they are functions within functions using return function to help classify them.
Example exercise
What we are trying to achieve: 1) index receivesAFunction(callback) receives a function and calls it:
function receivesAFunction(callbackFunction) { return callbackFunction(); }
This is a function that receives a function and calls it
2) index returnsANamedFunction() "before all" hook:
function returnsANamedFunction(fn){ return function name(){ return "Hello function my name is"; }; }
Because the returned function has the name of name this is what makes this a Named function with a return
3) index returnsAnAnonymousFunction() "before all" hook: working:
function returnsAnAnonymousFunction(){ return function (){ return "My name is Judge Judy";} ; }
Because the second function in returnsAnAnonymousFunction is completely empty but we have a return with a value this makes the function anonymous
github exercise with working:
















