Encode URI with JavaScript

Web Dev
Sponsored links

In this article, I will introduce how to encode URI with JavaScript.

What is URI?

URI is an abbreviation for Uniform Resource Identifier, which is a value for uniquely specifying a resource that exists on the Internet.
Resources are not limited to files, but there are various things such as voice data and functions(WebAPI).

A concrete example of a URI is a URL.
URL is an abbreviation for Uniform Resource Locator and represents an address on the Internet such as a web page.
In other words, URI exists as a big concept, and URL exists as one of the specification methods.

How to encode URI

The characters that can be used in the URI are limited.
Hiragana and Kanji cannot be used.
"Encoding" is a method of expressing those characters by URI.
Encoding replaces characters that cannot be used in URIs according to certain rules.

Use the encodeURI() function to encode the URI in JavaScript.
This method returns an encoded string.

encodeURI(URI)