URL encoding explained
URLs can only contain a limited set of ASCII characters. Characters outside that set — spaces, unicode, punctuation — must be percent-encoded: replaced with % followed by two hex digits representing the UTF-8 byte value. A space becomes %20, an ampersand becomes %26.
encodeURIComponent encodes everything except A–Z a–z 0–9 - _ . ! ~ * ' ( ). Use this for individual query parameter values.
encodeURI preserves URL structure characters like / ? # : @. Use this when encoding a full URL that should remain navigable.
Form encoding (application/x-www-form-urlencoded) additionally converts spaces to + instead of %20 — used in HTML form submissions.