0
const person = {
    name: "aman",
    age: 19,
    hello: [2,123,13,1,23],
    showDetails(){
        this.hello.forEach(function(items){
            console.log(this)   // referring to window object
        })
    }
}
person.showDetails()

and other is

const person = {
    name: "aman",
    age: 19,
    hello: [2,123,13,1,23],
    showDetails(){
        this.hello.forEach((items)=>{
            console.log(this)  // referring to person object
        })
    }
}
person.showDetails()

here in both cases the program is logging different output.

freedomn-m
  • 27,664
  • 8
  • 35
  • 57
  • 1
    Short answer: *Arrow functions and function declarations / expressions are not equivalent and cannot be replaced blindly* – freedomn-m Sep 01 '23 at 15:51

0 Answers0