2. Arrow Functions
Note that in the above example, the addition
arrow function is implemented with “concise body” which does not need an explicit return statement. Note the omitted after the =>
.
Here is an example with the usual “block body.” Including the curly brace wrappers.
Arrow functions don’t just make the code shorter. They are closely related to this
binding behavior.
Arrow functions behavior with keyword varies from that of normal functions. Each function in JavaScript defines its own this
context but arrow functions capture the this
value of the nearest enclosing context. Check out the following code:
As mentioned above, arrow functions capture the this value of the nearest enclosing context, so the following code works as expected, even with nested arrow functions.