Created
July 10, 2017 19:57
-
-
Save prof3ssorSt3v3/36d4e5c84616dfbd9e5bd27b514fd06e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 )); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice one