Symbol.for(key) returns the symbol registered under key in the runtime-wide registry, creating it on first use (namespace keys, e.g. 'app.session'). Symbol.keyFor(sym) returns that key or undefined. Registered symbols cannot be WeakMap keys (other symbols can, since ES2023) because they are never garbage-collected.
const k1 = Symbol.for('app.session');
console.log(k1 === Symbol.for('app.session'), Symbol.keyFor(k1), Symbol.keyFor(Symbol.iterator));
try { new WeakMap().set(k1, 2); } catch (e) { console.log(e.message); }true app.session undefined Invalid value used as weak map key