You probably typed the function without taking in count that in the code snippet we have the opening curly brace of the object BELOW the return, which means we are not returning it, we are returning nothing, therefore, the answer is B) undefined
If the opening curly brace was right next to return then it’d return the object.
If you see it that way I’m not going to argue man but if you get that kind of question in an interview you’d probably remember it, and that’s enough for me.
Any sensible interviewer will understand your way of thinking if you say it does return an object. That's not even close to some real life code. Also AFAIK this code is invalid if strict mode is enabled and that's a standard in 99% of companies I believe.
Well, if you fail an interview question because of such a "trick" from interviewer I think you shouldn't proceed with this particular employer.
P.S.: I'm working as a Typescript dev for about a decade, and quiz told me that I don't know JavaScript. Maybe I'm just mad because of it :D
2
u/[deleted] Jun 17 '23
I ran the code, got the same output