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

125
Views
how JS arrow function preserves its context?

in code snippet below:

  • in 1st case with arrow function - object logged

  • in 2nd case with function declaration - window logged

how and why does the arrow function preserve the context?

// 1ST CASE
function A() {
  this.getThis = () => {
    console.log(this)
  }
}

const a = new A

const aa = a.getThis
/* same as:
    const aa = () => {
    console.log(this)
  }
*/

aa() // object, context preserved O_o

// 2ND CASE
function B() {
  this.getThis = function() {
    console.log(this)
  }
}

const b = new B

// b.getThis() // will log object

const bb = b.getThis
/* same as:
    const bb = function() {
    console.log(this)
  }
*/

bb() // window

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!