Skip to content

Instantly share code, notes, and snippets.

@pbzona
Created May 24, 2018 13:14
Show Gist options
  • Save pbzona/5363d93e85e5c8965c7e7024be6833c5 to your computer and use it in GitHub Desktop.
Save pbzona/5363d93e85e5c8965c7e7024be6833c5 to your computer and use it in GitHub Desktop.
anonymous functions example
// "normal" way of writing (uses an anonymous function)
words.filter(function(word) {
return word.length < 6;
});
// arrow function (uses an anonymous function)
words.filter(word => word.length < 6);
// but you don't have to use an anonymous function...
// filter takes a function as an argument, and you can define that separately
// to reuse it other places, or make your code more readable
function checkIfShorterThanSixChars(n) {
return n.length < 6;
};
words.filter(checkIfShorterThanSixChars(word));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment