Understanding URL Percent-Encoding & Decoding (RFC 3986)
Uniform Resource Identifiers (URIs) require specific reserved characters to be percent-encoded whenever used inside query string keys or values. For example, spaces are represented by %20 or +, ampersands as %26, and question marks as %3F.
encodeURIComponent()
Encodes all special characters except A-Z a-z 0-9 - _ . ! ~ * ' ( ). Use this for individual parameters.
encodeURI()
Preserves valid URL delimiters such as ://, ?, &, and /. Ideal for complete URLs.
decodeURIComponent()
Restores hexadecimal escapes (like %20) into human-readable Unicode and ASCII characters.