Skip to content

Instantly share code, notes, and snippets.

@sukhmeet2390
Created August 2, 2016 15:33
Show Gist options
  • Save sukhmeet2390/19a63264ce015f9bbc8d61f4f6b01bdc to your computer and use it in GitHub Desktop.
Save sukhmeet2390/19a63264ce015f9bbc8d61f4f6b01bdc to your computer and use it in GitHub Desktop.
Arrow function examples
// 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