๐ง Contemplating a True Set
๐ง Equivalence in JavaScript: Contemplating a True Set In JavaScript, equivalence behaves differently depending on whether you're working with primitive or non-primitive types. For primitives —such as numbers, booleans, strings, and symbols—equivalence is determined by comparing actual values. If two variables hold the same value, they are considered equivalent. However, for objects and arrays , equivalence is by reference . Two arrays [0] and [0] are not considered equal because they are separate instances, even though they contain identical content. ๐ฌ Snippet 1: Equivalence by Value and by Reference new Set ([ 0 , 0 ]); // => Set { 0 } new Set ([[ 0 ], [ 0 ]]); // => Set { [0], [0] } JavaScript’s Set treats the two 0 values as equivalent but considers [0] and [0] as distinct because they are different object instances. This reveals JavaScript’s mini...