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

coderslang

Coderslang: Become a Software Engineer

Posted on February 5, 2021

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.

💖 💪 🙅 🚩
coderslang
Coderslang: Become a Software Engineer

Posted on February 5, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related