In this video, we will learn about JavaScript method URL.canParse().
The URL.canParse() static method of the URL interface returns a boolean indicating whether or not an absolute URL, or a relative URL combined with a base URL, are parsable and valid.
This is a fast and easy alternative to constructing a URL within a try...catch block. It returns true for the same values for which the URL() constructor would succeed, and false for the values that would cause the constructor to throw.
URL.canParse('https://example.com'); //true
URL.canParse('://brokenurl'); //false
URL.canParse('/path', 'https://example.com'); //true
🔔 Subscribe for more videos like this : https://www.youtube.com/c/CodeCanvas?sub_confirmation=1
#codecanvas #javascript #javascripttutorial