I can explain the difference between function declarations and function expressions.
- Function declarations do not declare
varwith a name before the function prior to the function keyword like function expressions do. With the expression, you cannot make a call to a function that is declared later in the file or it will throw an error because only thevarpart is hoisted to the top of the file, but the value of that (which is going to be a function) is still undefined. All function declarations (named functions) will be hoisted to the top of the file, so you can use them even before you actually defined them in the file.
I can explain what the value of this is in a normal function.
- global window
I can explain what the value of this is when called from the context of an object.
- the object
I can explain how to explicitly set the value of this in a function.
- You can use call to pass in an explicit 'this.' Call's first argument is whatever you want the value of 'this' to be.
I can explain the difference between call and apply.
- Apply takes an array of what the 'other' (non-this) arguments are, while call just takes the arguments directly. Use apply if you already have everything in an array.
I can describe an case where I might need to use bind to avoid polluting the global scope.
- If you actually use this to set a variable and this is the global window, then you've created a global variable (and not achieved your actual purpose). Instead you can use bind to ensure your function executes on the correct scope.
I can explain how bind works.
- Returns a copy of the function with 'this' set to a specific value that you provide.