Problem

What gets logged?

function getPort(url) {
  const { port } = new URL(url);

  if(port === '80') {
    console.log("You're using the default port");
  }

  if(port === '443') {
    console.log("You're using the default secure port");
  }

  console.log(`You are running on port "${port}"`);
}

getPort(`http://example.com:80`)
getPort(`http://example.com:8080`)
getPort(`https://example.com:443`)
getPort(`https://example.com:3000`)
Solution

What gets logged?

function getPort(url) {
  const { port } = new URL(url);

  if(port === '80') {
    console.log("You're using the default port");
  }

  if(port === '443') {
    console.log("You're using the default secure port");
  }

  console.log(`You are running on port "${port}"`);
}

getPort(`http://example.com:80`) // You are running on port ""
getPort(`http://example.com:8080`) // You are running on port "8080"
getPort(`https://example.com:443`) // You are running on port ""
getPort(`https://example.com:3000`) // You are running on port "3000"

The URL constructor function in JavaScript strips the default port even if it’s explicitly provided. Since port 80 is the default for http and port 443 is the default for https, the port is stripped from the URL resulting in an empty string. File this one away under JavaScript quirks that you probably don’t need to know, but could save future you hours of debugging.