Use toString() stringified method to convert URL to String in JavaScript. It will return USVString containing the whole URL read-only version of URL href.
const str_href = url.toString()
JavaScript URL to string Example code
HTML example code: should return the URL as a string.
<!DOCTYPE HTML>
<html>
<body>
<script>
var url = new URL("https://www.eyehunts.com");
console.log(url.toString());
</script>
</body>
</html>
Output:
Do comment if you have any doubts and suggestions on this JS URL topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version