r/JavaScriptTips • • Jun 16 '23

🧠 Test Your JavaScript Knowledge!

Can you predict the output of this JavaScript code snippet without running it? 🤔

A) {name: "Bing"}
B) undefined
C) SyntaxError
D) ReferenceError

1 Upvotes

10 comments sorted by

View all comments

Show parent comments

1

u/daidaicodes Jun 17 '23

Look at it again, pay attention to the details.

2

u/[deleted] Jun 17 '23

I ran the code, got the same output

2

u/daidaicodes Jun 17 '23

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.

4

u/mozilaip Jun 17 '23

So what knowledge are you checking? That's nitpicking, not attention to details

0

u/daidaicodes Jun 17 '23

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.

4

u/mozilaip Jun 17 '23 edited Jun 17 '23

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