I figured every new instance of an HTML element would be it's own distinct object, but hash tables are telling me differently. If I do:
document.createElement("button") === document.createElement("button")
I get the expected result of false
, but if I do:
let hash = {
[document.createElement("button")]: "choice 1",
[document.createElement("button")]: "choice 2"
}
console.log(hash);
then the result is: {[object HTMLButtonElement]: 'choice 2'}
, meaning the second button element overwrote the first button element even though they're supposedly different values. Does anyone know why that is? Can we not use elements as distinct keys in a hash table? If so, is there an alternate way of achieving what I have above?