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
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › encodeURI
encodeURI() - JavaScript - MDN Web Docs
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....
🌐
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
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....
🌐
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.
🌐
DEV Community
dev.to › juliafmorgado › the-difference-between-encodeuri-and-encodeuricomponent-2c0o
The difference between encodeURI() and encodeURIComponent() - DEV Community
September 28, 2022 - If you have a complete URL, use encodeURI. But if you have a part of a URL, use encodeURIComponent. ... Self-taught Full-Stack Web Developer breaking down what I've learned the hard way so you can learn it the easy way. ... #opensource #programming #codenewbie #tutorial Automatically Embed Latest Youtube Videos on your Website with JavaScript ...
🌐
DEV Community
dev.to › wanoo21 › difference-between-encodeuri-and-encodeuricomponent-j3j
Difference between encodeURI and encodeURIComponent - DEV Community
November 4, 2019 - There aren't big differences, the ... is that encodeURI() function encodes special characters, except: , / ? : @ & = + $ # whereas encodeURIComponent() function encodes special characters and in additional the characters which encodeURI doesn't encode...
🌐
Go Make Things
gomakethings.com › articles › whats-the-difference-between-encodeuri-and-encodeuricomponent-in-vanilla-js
What's the difference between encodeURI() and encodeURIComponent() in vanilla JS? | Go Make Things
The simple version: encodeURIComponent() encodes everything except these characters: A-Z a-z 0-9 - _ . ! ~ * ' ( ) encodeURI() ignores the same characters as encodeURIComponent(), and *also ignores these: ; , / ?
Find elsewhere
🌐
phpGrid
phpgrid.com › home › when to use encodeuri() and encodeuricomponent()?
When to use encodeURI() and encodeURIComponent()? | phpGrid - PHP Datagrid
March 25, 2022 - Use encodeURI if you have a whole URL. However, if you only have a portion of a URL, encodeURIComponent is the way to go. Technical readings: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent ...
🌐
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.
🌐
Coderwall
coderwall.com › p › y347ug › encodeuri-vs-encodeuricomponent
encodeURI() vs. encodeURIComponent() (Example)
September 2, 2017 - Turns out I was missing the point: encodeURI() will encode a URL string but not the parameters or hash. So: encodeURI("http://www.google.com/results with spaces#some-anchor") returns: http://www.google.com/results with spaces#some-anchor · ...
🌐
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. This simple rule exists because the two functions treat certain characters very differently.
🌐
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!
🌐
Medium
sarunnotes.com › understanding-encodeuri-and-encodeuricomponent-in-javascript-when-and-why-to-use-them-a03ee312b2f4
Understanding encodeURI and encodeURIComponent in JavaScript: When and Why to Use Them | by Sarun's Notes | Medium
November 30, 2024 - Understanding encodeURI and encodeURIComponent in JavaScript: When and Why to Use Them Mastering URL Encoding: The Differences Between encodeURI and encodeURIComponent in JavaScript As a JavaScript …
🌐
LinkedIn
linkedin.com › pulse › encodeuricomponent-encodeuri-javascript-parathan-thiyagalingam-kr8sc
encodeURIComponent & encodeURI in JavaScript
October 29, 2023 - const param = "example@domain.com"; const encodedParam = encodeURIComponent(param); console.log(encodedParam); // "example@domain.com" ... encodeURI: Used to encode an entire URI, including the scheme, authority, path, query, and fragment components...
🌐
DEV Community
dev.to › zhihu_wu_dea1d82af01a04d7 › encodeuri-vs-encodeuricomponent-the-javascript-url-encoding-trap-13p
encodeURI vs encodeURIComponent: The JavaScript URL Encoding Trap - DEV Community
May 31, 2026 - JavaScript gives us two encoding functions, and they serve different purposes: encodeURI() is designed for complete URLs. It keeps URL structure characters intact: /, ?, &, =, #, :, @, $, +, and ,. Use it when you have a full URL string and ...
🌐
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 ~!*().-_'
🌐
DEV Community
dev.to › shrutikapoor08 › javascript-url-encode-example-how-to-use-encodeuricomponent-and-encodeuri-2iph
JavaScript URL Encode Example – How to Use encodeURIcomponent() and encodeURI() - DEV Community
August 5, 2020 - If you have a complete URL, use encodeURI. But if you have a part of a URL, use encodeURIComponent. Interested in more tutorials and JSBytes from me? Sign up for my newsletter. or follow me on Twitter ... Staff Software Engineer. Writes about JS, React, GraphQL. Follow me on twitter.com/shrutikapoor08 ... #githubactions #javascript ...