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
- Use for query parameter keys/values, NOT full URLs: Encodes
/,?,&,=,#; for full URLs prefernew URL()+url.searchParams.set().
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
- tuts/javascript/builtins/Global/parseInt Linked here; links to this page; shared tags: #builtins, #global, #javascript, #tier, #web
- tuts/javascript/builtins/Global/queueMicrotask Linked here; links to this page; shared tags: #builtins, #global, #javascript, #tier, #web
- tuts/javascript/builtins/Global Linked here; links to this page; shared tags: #builtins, #global, #javascript, #web
- tuts/javascript/tutorials/core_syntax_and_types Linked here; shared tags: #javascript, #web
- tuts/javascript/builtins/Global/globalThis shared tags: #builtins, #global, #javascript, #tier, #web
- tuts/javascript/builtins/Global/isNaN shared tags: #builtins, #global, #javascript, #tier, #web
- tuts/javascript/builtins/Global/Number_isNaN shared tags: #builtins, #global, #javascript, #tier, #web
- tuts/javascript/builtins/Global/structuredClone shared tags: #builtins, #global, #javascript, #tier, #web
- tuts/javascript/builtins/Array/at shared tags: #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/filter shared tags: #builtins, #javascript, #tier, #web