Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is an Arrow function execution context?

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?
}
like image 353
AmerllicA Avatar asked May 26 '18 01:05

AmerllicA


People also ask

What is the context of arrow function?

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.

Is arrow function callback?

Arrow functions as callbacks Its this context refers to the global one, which in this case is the Window object.

How are arrow functions () => {} different than traditional function expressions?

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.


1 Answers

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.

like image 75
Bergi Avatar answered Sep 25 '22 16:09

Bergi