4 ms·
You’re being pedantic. Nobody is talking about internal representations, they’re saying it’s literally possible to key into a map with a float, which is true.
by kleinsch 4y ago
You’re being pedantic. Nobody is talking about internal representations, they’re saying it’s literally possible to key into a map with a float, which is true.
- cookiengineer 4y agoNo it's not, because they are talking about keying via Number.prototype.toString(), which is not keying via float but via its string representation. And that's my point, it's even part of the ECMAScript spec. See 6.1.6.1 and 6.1.7.1 [1] Additionally, a proof you can quickly tryout: object={}; object[-0]=123; object[+0]; // returns object["0"]; If Object key were a Number type, it would not use Number.prototype.toString(). You can literally create your own datatype and override valueOf() and toString() to play with this. [1] https://262.ecma-international.org/13.0/ https://262.ecma-international.org/13.0/
- chrisseaton 4y agoWhat do you think is happening when you use set with a float on a map? How do you explain this? const map = new Map(); map.set(1, 3); map.get(1); // 3 map.set(1.2, 3.4); map.get(1.2); // 3.4 typeof map.keys().next().value; // "number" Where do you think ‘number’ comes from? Read the spec - it supports primitives for keys and it doesn’t stringing them. As others have said in this thread - you’re just wrong.
- deleted 4y ago[deleted]