1//If body has single statement
2let myFunction = (arg1, arg2, ...argN) => expression
3
4//for multiple statement
5let myFunction = (arg1, arg2, ...argN) => {
6 statement(s)
7}
8//example
9let hello = (arg1,arg2) => "Hello " + arg1 + " Welcome To "+ arg2;
10console.log(hello("User","Grepper"))
11//Start checking js code on chrome inspect option
1const person = {
2 firstName: 'Viggo',
3 lastName: 'Mortensen',
4 fullName: function () {
5 return `${this.firstName} ${this.lastName}`
6 },
7 shoutName: function () {
8 setTimeout(() => {
9 //keyword 'this' in arrow functions refers to the value of 'this' when the function is created
10 console.log(this);
11 console.log(this.fullName())
12 }, 3000)
13 }
14}
1//ES5
2var phraseSplitterEs5 = function phraseSplitter(phrase) {
3 return phrase.split(' ');
4};
5
6//ES6
7const phraseSplitterEs6 = phrase => phrase.split(" ");
8
9console.log(phraseSplitterEs6("ES6 Awesomeness")); // ["ES6", "Awesomeness"]
10
1const greet = (who) => {
2 return `Hello, ${who}!`;
3};
4
5greet('Eric Cartman'); // => 'Hello, Eric Cartman!'
1// ES6
2const prices = smartPhones.map(smartPhone => smartPhone.price);
3console.log(prices); // [649, 576, 489]
4