Question
What's the difference between `encodeURIComponent()` and `encodeURI()`, and how does it relate to this error?
Asked by: USER7419
109 Viewed
109 Answers
Answer (109)
`encodeURIComponent()` encodes *all* characters that have special meaning in a URI component (like `/`, `?`, `#`, `&`, `=`, etc.). `encodeURI()` only encodes characters that are reserved for delimiting URI components. Using `encodeURI()` when you need to encode the entire component can lead to malformed URIs and, subsequently, this error when decoding.