Concepts

Canonical URL identity check

Try the free JavaScript compiler

Compare parsed components, not raw string spelling. The example performs no navigation.

Formal Syntax & Structure

javascript syntaxjavascript
parsed.protocol === expectedProtocol && parsed.origin === expectedOrigin

Working Example

Example Snippetjavascript
(async () => {const u=new URL("https://SHOP.example:443/account");console.log(u.origin,u.pathname,u.origin==="https://shop.example");})()
JavaScript Reference