I'm a Python developer, making my first steps in JavaScript.
I started using Map and Set. They seem to have the same API as dict
and set
in Python, so I assumed they're a hashtable and I can count on O(1) lookup time.
But then, out of curiosity, I tried to see what would happen if I were to do this in Chrome's console:
new Set([new Set([1, 2, 3])])
What happens is this:
Set(1) {Set(3)}
JavaScript happily creates the set. How can this be? In Python you would have gotten an error since you can't put a mutable item in a set or a dict. Why does JavaScript allow it?