Encode component vs. full URL
Encode component (encodeURIComponent) escapes every reserved character including / ? & = #. Use it for a single query parameter value.
Encode full URL (encodeURI) keeps the URL structure intact and only escapes characters that are not allowed anywhere in a URL, such as spaces and non-ASCII letters.
Why URL encoding matters
URLs may only contain a limited set of ASCII characters. Spaces, quotes, and characters from other languages must be percent-encoded (for example, a space becomes %20) or links and API requests can break.