How does the "this" keyword behave in arrow functions compared to regular functions?
- It refers to the global object.
- It retains the value of "this" from its enclosing lexical context.
- It becomes undefined.
- It refers to the parent function's "this".
In arrow functions, the value of "this" is determined by its enclosing lexical context (the function that contains it). This behavior is different from regular functions, where "this" is dynamically scoped and can change based on how the function is called. This makes arrow functions particularly useful for maintaining the expected value of "this" in functions defined within methods or callbacks.
Loading...
Related Quiz
- How do you declare a two-dimensional array in JavaScript?
- In what scenario might you prefer to use a function expression over an arrow function?
- What was the main reason for JavaScript's creation at Netscape?
- The ________ initiative aimed to standardize the core features of JavaScript.
- When defining a method in an object, the function associated with a property is referred to as a _________.