> For the complete documentation index, see [llms.txt](https://hemantajax-2.gitbook.io/es6-step-by-step/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hemantajax-2.gitbook.io/es6-step-by-step/arrow-function-and-this-scope.md).

# Arrow Function and this scope

```javascript
// ES5
var obj = {
    name: "Hemant",
    actions: ["Dance", "Sing", "Swim", "Run"],
    displayAction: function(){
        var self = this;
        this.actions.forEach(function(action){
            console.log(self.name + " can "+ action);
        });
    }
}

obj.displayAction();

// OR

var obj = {
    name: "Hemant",
    actions: ["Dance", "Sing", "Swim", "Run", "Eat"],
    displayAction: function(){
        this.actions.forEach(function(action){
            console.log(this.name + " can "+ action);
        }.bind(this));
    }
}

obj.displayAction();
```

## this with ES6 arrow function

```javascript
var obj = {
    name: "Hemant",
    actions: ["Dance", "Sing", "Swim", "Run"],
    displayAction: function(){
        this.actions.forEach(action => console.log(this.name + " can "+ action));
    }
}

obj.displayAction();
```
