DEV Community

loading...
Cover image for JS Test #5: Can you use an arrow function as a getter?

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

Coderslang: Become a Software Engineer
Teaching you to code at js.coderslang.com - JavaScript, HTML, CSS, Node.js, React.js, React Native
Originally published at learn.coderslang.com Updated on ・1 min read

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.

Discussion (0)