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}
1const greet = (who) => {
2 return `Hello, ${who}!`;
3};
4
5greet('Eric Cartman'); // => 'Hello, Eric Cartman!'
1/* Answer to: "arrow function javascript" */
2
3// Single-line:
4let testingFunc(string) => string == "Test" ? "Success!" : "Failure!";
5console.log(testingFunc("test")); // "Failure!"
6
7// Multi-line:
8let arrowFunc(string) => {
9 if (string = "test") {
10 return "Success!";
11 }
12 return "Failure!";
13 }
14};
15console.log(testingFunc("Test")); // "Success!"
16
17/*
18 Arrow functions in JavaScript are like regular functions except they look
19 look nicer (imo) and there's single-line version of it which implicitly
20 returns.
21
22 Here's a guide showing the differences between the two:
23 https://medium.com/better-programming/difference-between-regular-functions-and-arrow-functions-f65639aba256
24 > The link will also be in the source below.
25*/