0

I thought the output would be same in ()=>{} and function(){} but I got a different output.

  1. With function(){}

    var person = {};
    person.name = 'egoing';
    person.introduce = function(){
    return 'My name is '+this.name;
    }
    document.write(person.introduce());
    

the output was

'My name is egoing'
  1. But with ()=>{} function,

    var person = {};
    person.name = 'egoing';
    person.introduce = person.introduce=()=>{
    return 'My name is ' +this.name}
    document.write(person.introduce());
    

output was

'My name is '

Why is it differnt??

Dankim
  • 11
  • 1

0 Answers0