Skip to content
Advertisement

Outcome of [1][1] and [1][0] in JavaScript

I have a question regarding the outcome of this in JavaScript as I don’t really understand it. Why if I use this code it gets the next result:

JavaScript

How to explain the exact way of how JavaScript interprets these results?

Advertisement

Answer

Pretty simple actually, lets break it down:

JavaScript

Broken down is:

JavaScript

Same with b – but b uses the 0 index, which is defined (as 1);

a is undefined which is falsy, and b is 1 – which is truthy.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement