News for hackers. Stuff that matters.
Re:"@" on Twitter by marcins on Saturday April 28, 2018 @06:04AM (#16946932)
JavaScript object property keys are always strings, so technically it’s `arr[2]` that has the 2 coerced to a string.
Re:"@" on Twitter by Zalastax on Saturday April 28, 2018 @01:49PM (#16948729)
It's true that object keys are strings, but the array and object situation of JavaScript is quite confusing. Arrays are indexed by numbers, but still accept string indices, leading to behavior like this: https://stackoverflow.com/q/9526860
Re:"@" on Twitter by Legogris on Saturday April 28, 2018 @03:12PM (#16949028)
Actually, that is incorrect. Arrays are different in JavaScript. I don't have time to look up the exact reference, but to get an idea: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

> Arrays cannot use strings as element indexes (as in an associative array) but must use integers. Setting or accessing via non-integers using bracket notation (or dot notation) will not set or retrieve an element from the array list itself, but will set or access a variable associated with that array's object property collection. The array's object properties and list of array elements are separate, and the array's traversal and mutation operations cannot be applied to these named properties.