Last active
June 9, 2019 11:28
-
-
Save nutchy/74bd993a1f1919eef52b07eb56ad782d to your computer and use it in GitHub Desktop.
Arrow function in es6
This file contains hidden or 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
// 1. single line without return | |
function foo () { | |
console.log("Hello") | |
} | |
const foo = () => console.log("Hello") | |
// 2. single line with return | |
function foo () { | |
return "Hello" | |
} | |
const foo = () => "Hello" | |
console.log(foo()) | |
// 3. Multiple line without return | |
function foo () { | |
let a = 2 | |
let b = 3 | |
console.log(a + b) | |
} | |
const foo = () => { | |
let a = 2 | |
let b = 3 | |
console.log(a + b) | |
} | |
// 4. Multiple line with return | |
const foo = () => { | |
let a = 2 | |
let b = 3 | |
return a + b | |
} | |
// 5. Single line and pass args with return | |
const foo = a => a + 5 // return a + 5 | |
const foo = (a,b) => a + b // return a + b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment