Skip to content

Instantly share code, notes, and snippets.

@imtiazrayhan
Created February 23, 2018 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imtiazrayhan/f1a3f268b10dd509b0910293bbc46e17 to your computer and use it in GitHub Desktop.
Save imtiazrayhan/f1a3f268b10dd509b0910293bbc46e17 to your computer and use it in GitHub Desktop.
Arrow Functions Examples For Blog Post
//Array of birthyear.
const years = [1992, 1978, 1986, 1995];
//Calculating age with a normal function.
var ages = years.map( function(yr) {
return 2018 - yr;
});
console.log(ages);
//Calculating age with an arrow function.
const anotherAge = years.map(yr => 2018 - yr);
console.log(anotherAge);
//Arrow function example with single argument.
const multiply = number => number * 15;
console.log(multiply(5));
//Arrow function example with multiple arguments.
const nameAge = (name, age) => {
console.log(name, age);
}
nameAge('Imtiaz', 22);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment