Use encodeURIComponent to prepare one query parameter value or inspect percent-encoded text. Encoding a complete URL also escapes its colon and slashes, so identify the component you intend to encode.
Encode a&b 你好 to get a%26b%20%E4%BD%A0%E5%A5%BD. Decoding restores the original text; the encoded ampersand can safely belong to one parameter value.
encodeURI preserves some URL separators; encodeURIComponent is intended for individual component values. Form formats may interpret + differently. Re-encoding turns % into %25, so confirm how the input was produced before decoding it.
Data and network notes · More tool guides