AppDividend
Latest Code Tutorials

Javascript encodeURI Function Tutorial With Example

0

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.

 

Javascript encodeURI Function Tutorial

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.

Javascript encodeURI Function Tutorial With Example

 

// app.js

let y = "-_.!~*'()"
console.log(encodeURI(y))

The output is following.

 

Javascript encodeURI Function

Finally, Javascript encodeURI Function Tutorial With Example is over.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.