When and where should URL encoding be applied?
The difference between a complete URL and a query key or value, plus double-encoding failures.
URL encoding is usually applied to a query key or value, not to the entire URL. Encoding a complete address with `encodeURIComponent` also escapes structural separators such as `:` and `/`, making the result unusable as a direct URL.
What changed in this update?
Component encoding and form encoding are now separated with examples.
How do encodeURI and encodeURIComponent differ?
`encodeURI` preserves structural URL characters; `encodeURIComponent` escapes more characters inside one value. The URL and URLSearchParams APIs are safer than manual concatenation in new code.
How can you spot double encoding?
Encoding a percent sign turns `%` into `%25`. A value such as `%20` becoming `%2520` is a common sign of double encoding.
Why can a form use + for a space?
HTML form encoding may represent a space with `+`. General URL percent-encoding uses `%20`; the contexts should not be mixed.
Frequently asked questions
Should a domain name be encoded?
International domains use IDNA/Punycode rules, which are different from query component encoding.
Is decoded input safe?
No. A decoded value remains untrusted and needs context-appropriate escaping before use in HTML or commands.