Despite the fact that Set
is an Object, Object.freeze()
specifically operates on the properties of the object, a feature not utilized by Map and Set: for example
let m = new Map();
Object.freeze(m);
m.set('key', 55);
m.get('key'); // ==> 55
This behavior can be observed in Chrome, and it is likely standardized across browsers.
I am aware that it is possible to (occasionally) convert the Set or Map into a regular Object, and then freeze that object. However, this may lead to changes in key access between the frozen and unfrozen versions.