Default value for base in new URL

In the URL constructor documentation, it’s written that the parameter base has '' as default value. But using '' for base, I get the following error (same with Chromium or Node.js):

new URL('', '')
// Uncaught TypeError: URL constructor:  is not a valid URL.

With undefined or without base, the behavior is the same. The real default value is undefined?

Yes, I think you are right.

If you do new URL('foo', ''), then it works, and you end up with an href value of

If you do new URL('foo') or new URL('foo', undefined), then it fails because foo is not a value URL on its own.

If you do new URL('') or new URL('', undefined), then it works because is a valid URL on its own.

I’ll update the reference page as suggested.

1 Like