encodeURIComponent vs encodeURI
When to use each browser API and common pitfalls.
For query values, prefer encodeURIComponent so & and = do not break the URL.
For a full URL that only needs non-ASCII handled, encodeURI may fit.
Form encoding may use + for spaces — treat as space when decoding.
Decode errors usually mean a truncated or invalid % sequence.