TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The problem with new URL(), and how URL.parse() fixes that

3 pointsby kilianabout 1 year ago

1 comment

salil999about 1 year ago
In the example they have<p>&gt; const urlstring = &quot;this is not a URL&quot;;<p>&gt; const not_a_url = URL.canParse(urlstring) &amp;&amp; new URL(urlstring);<p>Why would you need the latter part of the condition? Couldn&#x27;t it just be this?<p>&gt; const isValidURL = URL.canParse(urlstring);