The problem with new URL(), and how URL.parse() fixes that (kilianvalkhof.com) 3 points by kilian 2y ago ↗ HN
[–] salil999 2y ago ↗ In the example they have> const urlstring = "this is not a URL";> const not_a_url = URL.canParse(urlstring) && new URL(urlstring);Why would you need the latter part of the condition? Couldn't it just be this?> const isValidURL = URL.canParse(urlstring);
1 comment
[ 3.1 ms ] story [ 12.3 ms ] thread> const urlstring = "this is not a URL";
> const not_a_url = URL.canParse(urlstring) && new URL(urlstring);
Why would you need the latter part of the condition? Couldn't it just be this?
> const isValidURL = URL.canParse(urlstring);