CKTIS / JavaScript
encodeURIComponent — encoding a URI component
encodeURIComponent encodes one URI component, such as a query parameter value. It converts special characters and non-ASCII characters into percent escapes representing UTF-8 bytes.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
encodeURIComponent(uriComponent)encodeURIComponent(uriComponent) is a global ECMAScript function, not a browser-only API. It converts its argument to a string and returns an encoded string. Use it for an individual value, not an entire address.
It leaves letters A–Z, a–z, digits 0–9, and - _ . ! ~ * ' ( ) unchanged. Other characters become UTF-8 bytes written as %HH. A space becomes %20, not +; a literal + becomes %2B.
Unlike encodeURI, it also encodes separators such as &, =, /, ?, and #. Encoding those characters keeps them from acting as delimiters when assembling a URI. The function leaves apostrophes and parentheses unchanged, though, and they can still act as delimiters in specific URI syntax, such as in OData URLs. It is not HTML escaping or address validation. Encoding the result again changes % to %25.
decodeURIComponent reverses the encoding of valid data. An unpaired UTF-16 surrogate in the argument to encodeURIComponent causes a URIError; the function does not automatically replace it. The example demonstrates encoding a Unicode character, a space, and separators, then checking reversibility.
Examples
const value = "ż &+/";
const encoded = encodeURIComponent(value);
console.log(encoded);
console.log(decodeURIComponent(encoded) === value);Result
%C5%BC%20%26%2B%2F true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.