Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

63
Views
this in array function in js

MDN: In arrow functions, this retains the value of the enclosing lexical context's this. In global code, it will be set to the global object:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this

I wrote this code:

const outerObj = {
      lemon:5,
      obj:{
        egg:5,
        apple: () => {console.log(this)}
      }
    }
    
    
    
    outerObj.obj.apple()

Why global object printed? my arrow function doesn't have her own this, so she looks for her outer scope, and it should be the "this" of obj, so I expect to see { egg: 5, apple: [Function: apple] }, what I missed?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!