ZeroKit URL Encoder vs encodeURIComponent in DevTools
encodeURIComponent() is the function both approaches ultimately rely on. The difference is whether you remember which of the two functions to call, and whether you need to encode a whole URL rather than one component.
| Dimension | ZeroKit | Browser DevTools console |
|---|---|---|
| Works on a component | Yes, encodeURIComponent semantics | encodeURIComponent() |
| Works on a full URL | Yes, encodeURI semantics, keeps :/?# | encodeURI() |
| Decode | Same page | decodeURIComponent() / decodeURI() |
| Shows the difference between the two modes | Yes, side by side | You have to know it |
| Available on a fresh machine | Open the page | Open DevTools (also fine) |
The mistake this prevents
encodeURIComponent() escapes ? & = and #, so encoding a whole URL with it breaks the query string. encodeURI() leaves those characters alone, which is what you want for a URL and not for a parameter.
Seeing both outputs side by side makes the distinction obvious in a way that reading documentation rarely does.
Questions
What is the difference between the two functions?
encodeURIComponent escapes every character that could have syntactic meaning in a URL, including / ? # & =. encodeURI leaves those intact and only escapes characters that are illegal in a URL, which is why it is used for whole URLs.
Does encoding double-encode % signs?
Yes: %25 is the escaped form of %. Encoding an already-encoded string escapes the % characters again, which is the usual cause of broken links with double encoding.
Try it without uploading anything
URL encoder and decoder for percent-encoding: convert with encodeURIComponent, encodeURI, decodeURIComponent or decodeURI, and parse query strings.
Open the free URL Encoder →