I'm trying to come up with a solution to a uniqueness problem in a program I'm writing using Sets and the has() method, but I'm running into the following problem. It seems like has() behaves differently based on if I build the variable inside the has() call (first code example, which returns false) versus if I initialize the variable before hand and pass it in (second example, which returns true).
I was hoping someone could shed some light on what's going on here as I don't want to introduce a bug into our code base.
const set1 = new Set([
{loc:"hello", x:1, y:2},
{loc:"Goodbye", x:1, y:2}
]);
console.log(set1.has(
{loc:"hello", x:1, y:2}
));
//outputs False
const elem = {loc:"hello", x:1, y:2};
const set1 = new Set([
elem,
{loc:"Goodbye", x:1, y:2}
]);
console.log(set1.has(
elem
));
//outputs True