Javascript EncodeURI Function Example Tutorial
Javascript encodeURI() is an inbuilt function that is used to encode a URI. The encodeURI() function encodes the Uniform Resource Identifier (URI) by replacing each instance of certain characters by one, two, three, or four escape sequences representing a UTF-8 encoding of a character. The encodeURI function encodes special characters, except: , / ? : @ & = + $ #. You might need to encode the URL if you are sending it as part of the GET request.
Javascript encodeURI Function Tutorial
The encodeURI() is useful to encode the full URLs.
The syntax of encodeURI() function is following.
encodeURI(uri)
Let’s see the example.
// app.js let uri = 'appdividend.com?name and author=krunal&age=26#link' let coded = encodeURI(uri) console.log(coded)
See the output.
It does not encode characters that have a special meaning (reserved characters) for a URI.
The encodeURI() function does not encode characters that are necessary to formulate a complete URI. Also, encodeURI does not encode a few additional characters, known as “unreserved marks,” which do not have a reserved purpose.
Let’s see some more examples.
// app.js let x = "KRUNAL 21" console.log(encodeURI(x))
See the output.
// app.js let y = "-_.!~*'()" console.log(encodeURI(y))
See the output.
Finally, Javascript encodeURI Function Example is over.
thanks for the guide