Skip to content

JavaScript URL to String | Read-only version of URL href

  • by

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:

JavaScript URL to String

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

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading