Created
February 23, 2018 00:13
-
-
Save imtiazrayhan/f1a3f268b10dd509b0910293bbc46e17 to your computer and use it in GitHub Desktop.
Arrow Functions Examples For Blog Post
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
//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