- What is URL encoding?
- URL encoding (percent encoding) replaces characters that are unsafe or reserved in URLs with a percent sign followed by two hexadecimal digits. For example, a space becomes %20, and an ampersand becomes %26.
- When do I need to URL encode?
- URL encoding is required when including special characters (spaces, &, =, /, #, ?, etc.) inside query parameter values. Without encoding, these characters would be misinterpreted as URL structural characters.
- What is the difference between encodeURI and encodeURIComponent?
- encodeURI() encodes a full URL and leaves structural characters like /, ?, &, and # intact. encodeURIComponent() encodes everything including those characters — use it when encoding individual query parameter names or values.
- Why does a space sometimes appear as + instead of %20?
- The + sign represents a space in application/x-www-form-urlencoded format (HTML form data), while %20 is the standard percent-encoding for spaces in URLs. Both are widely supported, but %20 is correct for URL paths and query strings.