DEV Community

Cover image for JS Test #5: Can you use an arrow function as a getter?
Coderslang: Become a Software Engineer
Coderslang: Become a Software Engineer

Posted on • Edited on • Originally published at learn.coderslang.com

JS Test #5: Can you use an arrow function as a getter?

code-snippet
Are there any issues with the getId function? What will be logged to the screen?

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

So, getId is an arrow function, thus it doesn’t have this of its own.

It’s not bound to this of the obj object and when we try to get this.id it will be evaluated to undefined and not 1.


ANSWER: undefined will be logged to the console.

Top comments (1)

Collapse
 
saurabh_tiwari_e2aaaf6ec7 profile image
Saurabh Tiwari

I have not understand this can you explain