Re:Oddities about JavaScript
by olavk on Monday May 30, 2011 @10:18AM
(#2599437)
My favorite oddity in JavaScript: Arrays are actually indexed by strings. arr[17] is just syntactic sugar for arr["17"].
[ Parent
| on HN ]
Arrays in JavaScript are merely objects with some extra bits tacked on to make them appear "array-like". Underneath they are still a collection of key/values like all other JS objects.
Re:Oddities about JavaScript
by justincormack on Monday May 30, 2011 @11:49AM
(#2599668)
But the "oddity" is that unlike many languages there are only string keys. Many languages implement the array type as a map but still distinguish between a[17] and a["17"].
Maybe I'm missing the point. I don't see how that is an oddity as all objects in JavaScript only allow string keys.
edit: JavaScript arrays are odd in general since they are just objects designed to look like "true" arrays. I guess I'm so used to that now that nothing about them feels "odd" anymore.