Lexical scoped this

Anonymous functions use dynamic scoping for this and arguments and use lexical scoping for all other variables. This behavior often causes error and unpleasant workarounds. Recall that rest parameters are preferable to arguments in modern JavaScript, but the this keyword is still a nemesis.

Dynamic scoped this in anonymous functions

Let’s look at an example that illustrates the odd behavior of this.

Get hands-on with 1200+ tech skills courses.