Every developer has encountered a URL that looks like hello%20world or q=foo%26bar. This is percent-encoding, also called URL encoding — and understanding it prevents a whole class of subtle bugs.
Why URLs need encoding
URLs use certain characters as delimiters: ? starts the query string, & separates parameters, # begins a fragment. If your data contains those characters they must be encoded, or the parser will misinterpret the URL's structure.
How it works
Each byte that isn't a safe ASCII character is replaced with a % followed by two hex digits representing that byte's value. A space becomes %20, & becomes %26, and so on.
encodeURI vs encodeURIComponent
encodeURI— encodes a full URL; leaves:/?#[]@!$&'()*+,;=intact because they're valid URL structure characters.encodeURIComponent— encodes a single component (query value, path segment); also encodes those delimiters. Use this for parameter values.
Common mistake
Building query strings by hand with string concatenation instead of URLSearchParams. URLSearchParams handles encoding automatically and correctly.
Test and convert URL encoding with ByteForge's URL Encode/Decode tool.