What is URL Encoding?
URL encoding (percent encoding) converts special characters into a format safe for URLs. Spaces become %20, & becomes %26, = becomes %3D. This is necessary because URLs can only contain certain ASCII characters.
Encode vs Decode
Encoding: Convert text to URL-safe format — use when building URLs or query strings. Decoding: Convert %20, %3D etc. back to readable text — use when reading URL parameters from logs or analytics.
What is the difference between encodeURIComponent and encodeURI?
encodeURIComponent encodes everything except letters, digits, and -_.!~*()' — use for query parameters. encodeURI skips : / ? # [ ] @ ! $ & ' ( ) * + , ; = — use for full URLs.
Why does a space become %20 or +?
In URL query strings, spaces can be encoded as either %20 (RFC 3986 standard) or + (HTML form encoding). Both are valid; %20 is more universally accepted.