If my URI-component (say a value for a query-string parameter) is a complete URL, should I use encodeURI() or encodeURIComponent()? OR BOTH like this: encodeURIComponent ( encodeURI (theCompleteURI )) ?
In other words does one of them also do the job of the other so I could just use one of them?
I'm also a bit confused as to why we need encodeURI() at all. If I enter a URL to the browser's location field should it not do the needed conversions for me? Or if I call a Node.js http-client library function should that not do the same as well?
The reason for encoding a URL would be so I can embed it as a query string value of a complete URL without breaking the containing URL I will then make the request for. But then shouldn't encodeURIComponent() be all that I need?
So I guess the 2nd part of my question is why should I use encodeURI(), when?
Is there a reason why encodeURI() could not also encode all its components? Or could I create my own version of it say encodeURI2() which does it all? Would it not make sense to have such a function built-in if it is possible?