Latest Code Tutorials

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.


Let’s see the example.

// app.js

let uri = ' and author=krunal&age=26#link'
let coded = encodeURI(uri)

See the output.

Javascript encodeURI Function Tutorial

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"

See the output.

Javascript encodeURI Function Tutorial With Example

// app.js

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

See the output.

Javascript encodeURI Function

Finally, Javascript encodeURI Function Example is over.

1 Comment
  1. Amit Parmar says

    thanks for the guide

Leave A Reply

Your email address will not be published.

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