It depends on what you are actually wanting to do.

encodeURI assumes that the input is a complete URI that might have some characters which need encoding in it.

encodeURIComponent will encode everything with special meaning, so you use it for components of URIs such as:

const world = 'A string with symbols & characters that have special meaning?'
const uri = 'http://example.com/foo?hello=' + encodeURIComponent(world)
Answer from Quentin on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › difference-between-encodeuri-and-encodeuricomponent-in-javascript
Difference Between encodeURI and encodeURIComponent in JavaScript - GeeksforGeeks
August 5, 2025 - encodeURI(URI) let uri = ... "https://www.example.com/search?query=hello world" ... The encodeURIComponent is a JavaScript function used to encode a URI component....
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › encodeURIComponent
encodeURIComponent() - JavaScript - MDN Web Docs
October 30, 2025 - The encodeURIComponent() function ... for characters composed of two surrogate characters). Compared to encodeURI(), this function encodes more characters, including those that are part of the URI syntax....
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › encodeURI
encodeURI() - JavaScript - MDN Web Docs
July 8, 2025 - The encodeURI() function encodes ... for characters composed of two surrogate characters). Compared to encodeURIComponent(), this function encodes fewer characters, preserving those that are part of the URI syntax....
🌐
DEV Community
dev.to › juliafmorgado › the-difference-between-encodeuri-and-encodeuricomponent-2c0o
The difference between encodeURI() and encodeURIComponent() - DEV Community
September 28, 2022 - encodeURI("http://www.example.org/a file with spaces.html") //http://www.example.org/a file with spaces.html · encodeURIComponent(): should be used to encode a URI Component such as individual values in the query string · `http://domain.c...
🌐
freeCodeCamp
freecodecamp.org › news › javascript-url-encode-example-how-to-use-encodeuricomponent-and-encodeuri
JavaScript URL Encode Example – How to Use encodeURIcomponent() and encodeURI()
August 4, 2020 - encodeURIComponent should be used to encode a URI Component - a string that is supposed to be part of a URL. encodeURI should be used to encode a URI or an existing URL.
🌐
phpGrid
phpgrid.com › home › when to use encodeuri() and encodeuricomponent()?
When to use encodeURI() and encodeURIComponent()? | phpGrid - PHP Datagrid
March 25, 2022 - encodeURI() should be used to encode an entire URI, and encodeURIComponent() should be used to encode a URI Component, which is a string that is expected to be part of a URL, which is similar to PHP rawurlencode function.
🌐
JavaScript in Plain English
javascript.plainenglish.io › encodeuri-vs-encodeuricomponent-a-javascript-developers-guide-a940c5ca086c
encodeURI vs encodeURIComponent: A JavaScript Developer’s Guide | by Ankur Raghav | JavaScript in Plain English
October 23, 2025 - Use encodeURI when you want to encode a complete, valid URL. Use encodeURIComponent when you want to encode a piece of a URL, like a query string parameter or a fragment.
Find elsewhere
🌐
Coderwall
coderwall.com › p › y347ug › encodeuri-vs-encodeuricomponent
encodeURI() vs. encodeURIComponent() (Example)
September 2, 2017 - encodeURI("http://www.google.com/results with spaces#some-anchor") returns: http://www.google.com/results with spaces#some-anchor · While encodeURIComponent() on the same string will return: http://www.google.com/results with spaces#some-anchor · What we actually want for a well formed URL is to call encodeURI() on the base URL: encodeURI("http://www.google.com/results with spaces") http://www.google.com/results with spaces ·
🌐
Julia Furst Morgado
julia.hashnode.dev › encodeuri-vs-encodeuricomponent
The difference between encodeURI() and encodeURIComponent()
September 28, 2022 - encodeURI("http://www.example.org/a file with spaces.html") //http://www.example.org/a file with spaces.html · encodeURIComponent(): should be used to encode a URI Component such as individual values in the query string · `http://domain.c...
🌐
The Art of Dev.
yon.fun › difference-between-encodeuri-and-encodeuricomponent
encodeURI vs encodeURIComponent or (how to not screw up with URI)
March 15, 2019 - There aren't big differences, the unique difference is that encodeURI() function encodes special characters, except: , / ? : @ & = + $ # whereas encodeURIComponent() function encodes special characters and in additional the above characters!
🌐
DEV Community
dev.to › wanoo21 › difference-between-encodeuri-and-encodeuricomponent-j3j
Difference between encodeURI and encodeURIComponent - DEV Community
November 4, 2019 - If you're encoding a string to put in a URL component (a query string parameter), you should use encodeURIComponent, and if you're encoding an existing URL, use encodeURI. It's simple!
🌐
Onux
docs.onux.com › en-US › Developers › JavaScript-PP › Language-Guide › encodeuri-vs-encodeuricomponent
encodeURI vs encodeURIComponent | JS++ & JavaScript Documentation
Most importantly, we can see that the && string is not escaped with encodeURI; yet, encodeURIComponent will escape too much data.
🌐
Toolify
toolify.ai › ai-news › decode-the-secrets-encodeuri-vs-encodeuricomponent-100419
Decode the Secrets: encodeURI vs encodeURIComponent
December 26, 2023 - The encodeURI() method is used to encode a complete URL, including the protocol, domain name, and path. It excludes certain characters from encoding, such as uppercase letters, lowercase letters, numbers, hyphens, underscores, periods, exclamation marks, and tildes.
🌐
Wordpress
alanristic.wordpress.com › 2013 › 02 › 16 › javascript-escape-vs-encodeuri-vs-encodeuricomponent
Javascript: escape() vs. encodeURI() vs. encodeURIComponent() – Alan Ristić
February 16, 2013 - The best alternative is usually encodeURIComponent(). This function encodes special characters, except: * @ - _ + . / Use of the encodeURI() method is a bit more specialized than escape() in that it encodes for URIs as opposed to the querystring ...
🌐
Medium
frankie95.medium.com › encodeuri-encodeuricomponent-you-should-know-the-differences-a58426b9f91a
encodeURI & encodeURIComponent You should know the differences | by Frankie | Medium
October 13, 2020 - encodeURI will not encode ASCII alphabet, number and ~!@#$&*()=:/,;?+.-_' encodeURIComponent will not encode ASCII alphabet, number and ~!*().-_'
🌐
Edgecompute
js-compute-reference-docs.edgecompute.app › encodeuricomponent
encodeURIComponent | @fastly/js-compute
The encodeURIComponent() function ... for characters composed of two surrogate characters). Compared to encodeURI(), this function encodes more characters, including those that are part of the URI syntax....
🌐
GitHub
github.com › parse-community › parse-server-s3-adapter › issues › 75
encodeURI vs. encodeURIComponent · Issue #75 · parse-community/parse-server-s3-adapter
October 7, 2019 - This encodes objectKey. objectKey can have / character. (eg. w200/myImg.png). encodeURIComponent encodes / to /. encodeURI does NOT encode /.
Author   parse-community