Encode and decode URI components to ensure they are safe for use in URLs.
URL (percent) encoding replaces characters that aren't safe in a URL — spaces, &, =, ?, and others — with a % followed by their hex code, so query strings and path segments don't break when they contain those characters.
Anytime you're building a query string or URL path manually and the value might contain spaces, &, #, or other reserved characters — for example encoding a search term before appending it to a URL.
It's built for encoding individual components (like a query parameter value), using encodeURIComponent-style rules — not full URLs, where you'd want to leave the scheme and structural characters untouched.