I was reading a Execution Context in JavaScript
article, and I undoubtedly understand what is execution context in JavaScript
.
function Foo() {
// Execution context of Foo function is here, between curly braces
}
Also I read about Arrow Functions
and its properties, But a question arose for me:
Where is an Arrow function execution context?
const ArrowFoo = () => {
// Where is ArrowFoo function execution context?
// Is here? or the upper block scope?
// Or global scope?
}
Arrow function and this context. this represents an object that executes the current function. In short, this is defined by the function execution context. Such as how a function is called, it refers to a global object window. For example, when a function is being executed from a global object.
Arrow functions as callbacks Its this context refers to the global one, which in this case is the Window object.
Regular functions created using function declarations or expressions are constructible and callable. Since regular functions are constructible, they can be called using the new keyword. However, the arrow functions are only callable and not constructible, i.e arrow functions can never be used as constructor functions.
The execution context of an arrow function is a function execution context like for all other functions.
Similar too foo
, the body of the arrow function (between the curly braces) contains the code that executes in this execution context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With