Javascript
JavaScript Fundamentals -- The this Keyword

Arrow Functions

PRO
Outline

Arrow functions in JavaScript work a little differently than named functions. As we've seen throughout this course, named functions (a standard function with the function keyword, opening and closing parens, and open and closing curly brackets) get their own context. If they're called on an object or with the .call, .apply, or .bind method, their context is the object with which they're called. They also get a new object for context if they're called using the new keyword. If none of those situations is true though, they default to the global context or undefined if in strict mode.

Arrow functions, though, don't follow that same pattern. They always will only use the context that surrounds where they're called. So if they're used inside a named function, their context is the same as that named function. If they're not called inside a named function, their context defaults to the global context or undefined if in strict mode.

For more information on this in JavaScript, go read this blog post.

 

I finished! On to the next chapter