s1 = Symbol.for('cat')
s2 = Symbol.for('cat')
s1 === s2 // true
The most common use-case for them is to generate symbols that don't collide, though. s1 = Symbol.for('cat')
s2 = Symbol.for('cat')
s1 === s2 // true
The most common use-case for them is to generate symbols that don't collide, though.Looks like an anti-pattern to me.
If you want one particular symbol from some library, you could import it.
s1 = Symbol("cat");
s2 = Symbol.for("cat");
s3 = Symbol.for("cat");
s1 == s2; // false
s2 == s3; // true
You can still have Symbols outside the registry.