DEV Community

Discussion on: Can You Guess the Result of This JavaScript Code?

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

Did you mean to leave x unused, or is that a mistake in your example?

Either way, after line 3 the array [undefined, "b"] so whether you index it with ["1"] or with [x], the result is going to be b

Collapse
 
firecrow8 profile image
Firecrow Silvernight

Your right that x was unused, I've removed that. That's true, the reason I posted this is because arrays are slightly different from object bracket access.

but yes it's b