Difference between encodeURIComponent() and encodeURI()
There are no big differences, the only difference is that the encodeURI() function encodes special characters, except:
, /? : @ & = + $ # while the encodeURIComponent() function encodes special characters and in addition the above characters(
, /? : @ & = + $ #).
var url = 'https://stackhowto.com/search?q=' var req = 'St@ckHowTo' // encode only the string 'req' with encodeURIComponent var url1 = url + encodeURIComponent(req) console.log(url1) //Output: https://stackhowto.com/search?q=St%40ckHowTo // encode only the string 'req' with encodeURI var url2 = url + encodeURI(req) console.log(url2) //Output: https://stackhowto.com/search?q=St@ckHowToMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More