Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11JavaScript’s built-in encodeURIComponent() leaves a straight apostrophe (') unchanged. For example, encodeURIComponent("it's") returns it's, not it%27s. That is documented behavior, not a bug. If the system receiving the value requires apostrophes to be percent-encoded, add a replacement step.
Why does encodeURIComponent() leave an apostrophe unchanged?
encodeURIComponent() encodes a value as one URI component, rather than encoding an entire URL. Its documented set of characters that it does not escape includes letters, digits, and - _ . ! ~ * ' ( ). The straight ASCII apostrophe, U+0027, is therefore passed through literally. See MDN’s encodeURIComponent() reference.
This behavior is distinct from encoding URI structure: for example, the function does encode characters such as & so they are not mistaken for separators within a component. A literal apostrophe may still be acceptable to the system handling the component; whether it must be escaped depends on that system’s encoding requirements.
How can I encode a single quote as %27?
If the target requires the stricter RFC 3986 convention, apply the additional replacements shown in MDN’s RFC 3986 example. It escapes !, ', (, ), and * after calling the built-in function:
#1 Best Overall
function encodeRFC3986URIComponent(str) {
return encodeURIComponent(str).replace(
/[!'()*]/g,
(c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`,
);
}
encodeRFC3986URIComponent("it's"); // "it%27s"
The helper produces uppercase hexadecimal escapes, including %27 for the apostrophe. This is a stricter encoding convention, not a fix for a defect in encodeURIComponent(). Use it when the receiving system calls for those reserved characters to be percent-encoded; otherwise, the built-in function’s component encoding may be sufficient. RFC 3986 identifies these characters as reserved in its reserved-character list.
What if the input contains a typographic apostrophe or a malformed surrogate?
The example concerns the straight ASCII apostrophe, U+0027. A typographic apostrophe such as U+2019 is a different character and is not part of the function’s documented unescaped set, so it is percent-encoded when passed to encodeURIComponent().
Rank #2
The function throws a URIError if the input contains a lone surrogate. MDN documents this exception and suggests String.prototype.toWellFormed() as one way to replace lone surrogates before encoding. See MDN’s lone-surrogate guidance.
Quick Recap
Best Value
Rank #4
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitches




