3 ms·
What runtime did you use for that? JavaScript maps absolutely can use numbers (or any type) as keys, but that's not how its API works. Square brackets access o
by matt_kantor 4y ago
What runtime did you use for that?
JavaScript maps absolutely can use numbers (or any type) as keys, but that's not how its API works. Square brackets access object properties, but map entries are not stored like that, and that last `typeof` is `"undefined"` in every runtime I tried (not `"number"`). Try `map['set']` to see another example.
Here's what I think you meant:
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"
- chrisseaton 4y agoSquare brackets were a typo - I didn't run it I just wrote it off the top of my head. Doesn't your correct prove what I said though?
- matt_kantor 4y agoWe're certainly in agreement that cookiengineer's "ECMAScript does not have maps where keys can be integers and neither can keys be floats" assertion is dead wrong.