This solution is generated by ChatGPT, correctness is not guaranteed. You might also be able to find a solution fromcommunity posts.
AI solution for JavaScript Quiz on BFE.dev
102. Arrow Function II
The code will output:
undefined
"BFE"
undefined
The first getName1()
function returns undefined
because the this
keyword within the function refers to the inner function's scope rather than the class's scope. The second getName2()
function correctly returns the name
property of the class because it uses an arrow function, which preserves the this
keyword to refer to the class's scope. The third getName3()
function also returns undefined
because it uses a regular function declaration, which creates a new this
binding within the function.