Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Can anyone tell me should I use encodeURI or encodeURIComponent  for encoding URLs? 

1 Answer

0 votes
by (19.7k points)

It depends on the usage you are looking for. If you use encodeURI, the input is assumed to be a complete URI. For encodeURIComponent, it encode all with special meaning which can be used with the below components:

var world = "A string with symbols & characters that have special meaning?";

var uri = 'http://example.com/foo?hello=' + encodeURIComponent(world);

Interested in Java? Check out this Java tutorial by Intellipaat.   

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...