- I can explain the difference between function declarations and function expressions.
Yes.
function declaration - this entire function gets hoisted
function someThing(x) {
console.log("stuff");
}
function expression - only the name of the variable gets hoisted and will return undefined until the actual line of code is run
var someThing = function(x) {
console.log("stuff");
};
- I can explain what the value of
thisis in a normal function.
The global object / window
- I can explain what the value of
thisis when called from the context of an object.
Whatever object it's being called from.
- I can explain how to explicitly set the value of
thisin a function.
Yes, with .call(), .apply(), or bind()
- I can explain the difference between
callandapply.
With .call() we send in whatever we want this to be and each of our arguments. With .apply() we also send in what we want this to be but can then send in an array that will get split into our individual argements.
- I can describe an case where I might need to use
bindto avoid polluting the global scope.
With ansyncronous things - we bind this to the function we will use when we get all our data back.
- I can explain how
bindworks.
It hands us back a new function replacing this with a hard set value that we determine.