On this page
  1. Global.encodeURIComponent
  2. Signature & Overview
  3. Notes & Pitfalls
  4. Example

Global.encodeURIComponent

Prev: parseInt | Up: Global | Next: queueMicrotask
Rel: Global, JS Core Syntax & Types
Ref: MDN Web Docs — Global.encodeURIComponent
Tags: #public #web #javascript #builtins #global #tier/core


Signature & Overview

encodeURIComponent(str)  /* + decodeURIComponent() */

Percent-encodes a single URI query parameter value safely.

Notes & Pitfalls

Example

const q = "a & b = 100%";
const url = `https://example.com/search?q=${encodeURIComponent(q)}`;
console.assert(url.includes("a%20%26%20b%20%3D%20100%25"));

Linked from

Related notes