Created
August 2, 2016 15:33
-
-
Save sukhmeet2390/19a63264ce015f9bbc8d61f4f6b01bdc to your computer and use it in GitHub Desktop.
Arrow function examples
This file contains 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
// ES5 way | |
var square = function(x){ | |
return (x*x); | |
} | |
// ES6 way | |
var square = (x) => { return x*x }; | |
// if expression has only 1 line we can even drop the braces | |
var square = x => x*x; | |
var players = ['Dhoni', 'Yuvi', 'Virat']; | |
// ES5 way | |
var len = players.map(function(el){ return el.length; }); | |
//ES6 way | |
var len = players.map(el => el.length); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment