+ 1
Why is this code outputting 21
4 Réponses
+ 3
E∆SI 🇳🇬 Before your alert on line 4, you have an array of length 3 like this:
var a = new Array();
a = [, 2, 1]
So, alert([2] + a.length - a[1]) will convert the first part which is an array with 2 to a string "2" because of the + operator. Your array.length is 3 because you inserted two items in index positions 1 and 2, so a placeholder item exists in index position 0.
Now we have "2" + 3 which becomes the string "23".
You then subtract from that the item at index position 1 of your array which is 2.
The final calculation is "23" - 2 which comes to "21".
+ 3
CamelBeatsSnake
🅰🅹 (Challenge Accepted)
Thanks so much
+ 2
E∆SI.py 🇳🇬
Because [2] + 3 - 2 = [2] + 1 = 21
0
E∆SI 🇳🇬 You're welcome.