Skip to content

Instantly share code, notes, and snippets.

@afshinator
Last active January 7, 2021 17:17
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save afshinator/9867199 to your computer and use it in GitHub Desktop.
Save afshinator/9867199 to your computer and use it in GitHub Desktop.
Javascript - Focus on Functions
--> Focus on FUNCTIONS IN JAVACRIPT
### Using callbacks in JavaScript (how to pass functions as arguments to other functions)
function doSomethingCool() {
//
}
$('someElement').click( doSomethingCool );
### Passing named functions vs. passing anonymous functions
Same thing as above using anon function:
$('someElement').click( function() {
// contents of anonymous function.
});
$('someElement').click( function(){ } ); // same as above on one line
### Composing and writing functions
### What arguments are provided to each function, and what are their types?
The arguments object is a local variable available within all function.
It is similar to an Array, but does not have any Array properties except length.
Other Properties
arguments.callee : Reference to the currently executing function.
### What gets returned out of a function, if anything?
If you don't specify, then undefined is returned,
return; // Also, return by itself like this returns undefined too.
### How and when do you use anonymous functions?
When you don't need to pass the same function anywhere else, there's no need to name it.
### What does it mean to be a higher-order function, and how are they composed?
Functions that either take in other functions as parameters, or functions that return functions.
So, callbacks are higher order functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment