Skip to content
ZeroKit

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.

DimensionZeroKitBrowser DevTools console
Works on a componentYes, encodeURIComponent semanticsencodeURIComponent()
Works on a full URLYes, encodeURI semantics, keeps :/?#encodeURI()
DecodeSame pagedecodeURIComponent() / decodeURI()
Shows the difference between the two modesYes, side by sideYou have to know it
Available on a fresh machineOpen the pageOpen 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 →

More comparisons