DEV Community

Discussion on: Structure of URL

Collapse
peerreynders profile image
peerreynders
const url = new URL(
  'http://tim:secret@wwww.example.com:8080/home?params=09#id'
);
console.log(url.protocol); // 'http:'      aka [ scheme ':' ]
console.log(url.username); // 'tim'                       
console.log(url.password); // 'secret'                       
console.log(url.origin);   // 'http://www.example.com:8080'
console.log(url.host);     // 'www.example.com:8080'
console.log(url.hostname); // 'www.example.com' 
console.log(url.port);     // '8080'
console.log(url.pathname); // '/home'      aka path
console.log(url.search);   // '?params=09' aka [ '?' query]
console.log(url.hash);     //  '#id'       aka [ '#' fragment ]
Enter fullscreen mode Exit fullscreen mode

MDN: URL

The naming is largely inspired by

Collapse
ndrohith profile image
Rohith ND Author

Wow ! This appears to be rather interesting. Thank you for bringing this to our attention. I'm hoping that this will be useful to a large number of people, including myself.