Here is a javascript trivia problem that gives you something to think about.
Go to your console and run below line.
++[1,2,3][2]
Can you exaplain the output ?
Here is a javascript trivia problem that gives you something to think about.
Go to your console and run below line.
++[1,2,3][2]
Can you exaplain the output ?
For further actions, you may consider blocking this person and/or reporting abuse
ramadhan.dev -
James -
nobody-99 -
Jonathan Gamble -
Top comments (4)
The array selection has a higher operator precedence than the increment by one, so first the item with index
2
from the array is selected, which happens to be 3; this is then incremented by one so you get 4.Yup. That's exactly the case.
If you write as this then it all make sense :
There's a tiny mistake in your adaption:
x++
increments x, but returns the previous value, whereas++x
increments x, but returns the new value.I get 4 and am not sure how to explain the output 🙃