DEV Community

FatimaAlam1234
FatimaAlam1234

Posted on • Updated on

JS - This

Image description

Image description

arrow function does not have it's own this and takes the global one.

Image description

Image description

Argument keyword only works in the normal function and not arrow ones.

When we try to access a property of an object which is not defined yet we get -> undefined instead of an error

We should use normal function instead of arrow function coz if we make it a habit we don't have to think about scope of "this

The scope an arrow function takes inside a method is same as if it's declared outside it.

Image description

To preserve the scope we use self ->

Image description

A normal function inside another method will have the this keyword undefined or will behave as if it's declared outside that method
but an arrow function (since it takes lexical scope) it takes the scope of the method and this is defined by the scope of that method instead of it's outside environment.

Top comments (0)