customElements.get('name') checks the browser’s custom-element registry and returns the class constructor associated with that tag. If no class is registered, it returns undefined. This makes it a small but useful guard before calling customElements.define, which throws when the same name is registered twice. section 2.3 section 14.2
if (!customElements.get('my-custom-tag')) {
customElements.define('my-custom-tag', class extends HTMLElement {});
}
Guard a custom-element definition so repeated loading or importing does not register the same tag twice. section 2.3
Avoiding a duplicate definition
if (!customElements.get('my-custom-tag')) { customElements.define('my-custom-tag', class extends HTMLElement {}); } The condition is true only when the registry has no constructor for the name, so the definition runs once. This pattern is especially useful when component code may be loaded from more than one place. section 2.3
