0

I saw this question in a quiz, how is a fat arrowed question works? is there any difference in the following code, if if yes why, if no why?:

    var abc = function() {
        return {
          log : function() {
            console.log(this.val);
          }
        };
    }

    var def = function(){
        return{
          log : () => {
            console.log(this.val);
          }
        };
    }
pragya.go
  • 169
  • 1
  • 10

1 Answers1

0

A fat arrow function automatically binds to this. It help avoid code where you have to save this in some other variable like that... such as in deeply nested callback hell. It is also more terse.

skellertor
  • 602
  • 5
  • 21