What is the difference between encodeURI and encodeURIComponent?
encodeURI preserves full URL structure (leaving ://, ?, & intact); encodeURIComponent encodes all reserved characters and is intended for individual query parameters.
Percent-encode or decode a URL or query string.
Encodes reserved and non-ASCII characters into standard percent-encoded escape sequences (%XX) and decodes URL strings safely.
Encoded_URL = encodeURIComponent(String) | Decoded_URL = decodeURIComponent(Encoded_String)
Replaces unsafe URI characters with a '%' symbol followed by two hexadecimal digits representing their UTF-8 byte values (e.g. space -> %20).
Inputs: Raw String: 'name=Rahul Sharma & co=Calciverse!'
Summary: Plaintext = 'Rahul Sharma & co' | Encoded = 'Rahul%20Sharma%20%26%20co'
encodeURI preserves full URL structure (leaving ://, ?, & intact); encodeURIComponent encodes all reserved characters and is intended for individual query parameters.
%20 is standard percent-encoding; the '+' character is used specifically in application/x-www-form-urlencoded form submissions.
Unreserved characters: alphanumeric letters (A-Z, a-z), decimal digits (0-9), and hyphen (-), underscore (_), period (.), and tilde (~).