Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Created July 10, 2017 19:57
Show Gist options
  • Save prof3ssorSt3v3/36d4e5c84616dfbd9e5bd27b514fd06e to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/36d4e5c84616dfbd9e5bd27b514fd06e to your computer and use it in GitHub Desktop.
// ES6 (fat) Arrow functions
//work best in callback function scenarios
// parentheses around input if more than one
// curly braces around function body if more than one line/command
// return only needed if more than one line of code
let numbers = [123, 234, 345, 456, 567];
let names = ['Alex', 'Bree', 'Cara', 'Cole', 'Devon', 'Riley'];
//simple function syntax
//create a new array of the values from the array greater than 300
let big = numbers.filter(function(item){
return item > 300;
});
//arrow function version
let bigA = numbers.filter( item => item > 300 );
console.log(big);
console.log(bigA);
names.forEach( function(item, index){
console.log( index, item);
});
names.forEach( (item, index) => console.log( index, item ));
@mina-adibe
Copy link

nice one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment