Percent-encode or decode URLs and query strings, and break a URL into its parts and query parameters.
URL encoding replaces characters that are not allowed or have a special meaning in a URL with a % followed by their UTF-8 bytes in hex, for example a space becomes %20 and ç becomes %C3%A7.
encodeURIComponent also encodes reserved characters such as / ? & = and #, so it is the right choice for a single query value or path segment. encodeURI leaves those characters alone and is meant for encoding a complete URL without breaking its structure.
%20 is valid everywhere in a URL. The + sign means a space only in application/x-www-form-urlencoded data, such as HTML form submissions and most query strings, so enable the + option when working with form data.
Decoding fails when a % is not followed by two hexadecimal digits, or when the bytes do not form valid UTF-8 (for example %E7 alone, which is a Latin-1 encoded ç). Fix or encode the stray % as %25 and try again.