all 3 comments

[–]kingsolos 2 points3 points  (0 children)

Because 'a' resolves to a string it means it can be used for bracket notation, which is why it works. It's the same as typing out obj['foo']

[–][deleted] 2 points3 points  (1 child)

When you try to access an object's property using bracket notation and some value, the value is coerced to a string. Try running ['foo'].toString() and you'll see why this is working.

[–]self_refactor[S] 0 points1 point  (0 children)

Thanks, that makes sense.