Friday, 29 March, 2019 UTC


Summary

Javascript encodeURI Function Tutorial With Example is today’s topic. The encodeURI() function is used to encode a URI. The encodeURI() function encodes the Uniform Resource Identifier (URI) by replacing the 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)
The output is following.
 
It does not encode characters that have 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))
The output is following.
 
// app.js

let y = "-_.!~*'()"
console.log(encodeURI(y))
The output is following.
 
Finally, Javascript encodeURI Function Tutorial With Example is over.
The post Javascript encodeURI Function Tutorial With Example appeared first on AppDividend.