Skip to content

Instantly share code, notes, and snippets.

@nutchy
Last active June 9, 2019 11:28
Show Gist options
  • Save nutchy/74bd993a1f1919eef52b07eb56ad782d to your computer and use it in GitHub Desktop.
Save nutchy/74bd993a1f1919eef52b07eb56ad782d to your computer and use it in GitHub Desktop.
Arrow function in es6
// 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