Reputation: 51876
I was surprised to see this answer to a challenge, because I had no idea this syntax was legal. Namely, the part that looks like this (I simplified it a bit):
"eo"[0,g=()=>{},g(),g(),1]
To me, this looks like an array literal is being used to access an object key. Is this documented behavior in JavaScript? For the record, it looks like the last value of the array is what gets dereferenced.
Upvotes: 2
Views: 165
Reputation: 386570
Its the use of the comma operator for an access of a string, basically this returns o
, and does something in between.
In parts:
"eo" string
[ bracket operator/string accessor
0, value 0
g=()=>{}, generating an empty function
g(), call that function
g(), call that function again
1 take 1 as the last element of comma operator
] return 'o'
Upvotes: 1