Skip to content

Instantly share code, notes, and snippets.

@danoctavian
Last active November 20, 2018 10:43
Show Gist options
  • Save danoctavian/faf3668d4defd91483e9203cf204370c to your computer and use it in GitHub Desktop.
Save danoctavian/faf3668d4defd91483e9203cf204370c to your computer and use it in GitHub Desktop.
javascript function declaration VS function expression
function f(x) {
console.log(`x this ${this}`)
return y(x) + 1
}
// calling this here works, y is hoisted
console.log(f.bind(123)(3))
function y(y) {
console.log(`y args ${arguments[0]}`)
console.log(`y this ${this}`)
return y * 2
}
const g = (x) => {
console.log(`g this ${this}`)
return z(x) + 1
}
// calling this here will crash because lack of z
// console.log(g.bind(123)(3))
const z = (x) => {
console.log(`z args ${arguments[0]}`)
console.log(`z this ${this}`)
return 2 * x
}
console.log(g.bind(123)(3))
// REDECLARATION
// the below is legal, doesn't throw
// function f() { console.log('REDECLARED') }
// the below won't work
// const f = (x) => x + 10000
@fedealconada
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment