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 › encodeURIComponent
encodeURIComponent() - JavaScript | MDN
The encodeURIComponent() function encodes a URI by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two surrogate characters).
🌐
W3Schools
w3schools.com › jsref › jsref_encodeuricomponent.asp
JavaScript encodeURIComponent() Method
❮ Previous JavaScript Global Methods Next ❯ · Encode a URI: let uri = "https://w3schools.com/my test.asp?name=ståle&car=saab"; let encoded = encodeURIComponent(uri); Try it Yourself » · The encodeURIComponent() method encodes a URI component.
Discussions

javascript - Should I use encodeURI or encodeURIComponent for encoding URLs? - Stack Overflow
Which of these two methods should be used for encoding URLs? More on stackoverflow.com
🌐 stackoverflow.com
JavaScript's equivalent of encodeURIComponent() method in golang
url.QueryEscape is probably the one you're looking for. Here's a playground link: https://play.golang.org/p/Fim4gcn-ZJa More on reddit.com
🌐 r/golang
13
5
February 24, 2019
Using encodeURIComponent and decodeURIComponent
In my experience i never had to use decodeUriComponent. If you use next searchparams it always decode by itself. but if you construct complex searchparams in your app you cant go without encodeuriparam More on reddit.com
🌐 r/nextjs
7
1
February 3, 2024
encodeURIComponent and decodeURIComponent
I’m send json through a webform where the values are encoded using Javascript’s encodeURIComponent, to prevent errors in the json file for special characters etc. How can I decode this now in Make.com? More on community.make.com
🌐 community.make.com
5
0
February 19, 2024
🌐
TutorialsPoint
tutorialspoint.com › article › encodeuricomponent-function-in-javascript
encodeURIComponent() function in JavaScript
March 15, 2026 - The encodeURIComponent() function accepts a string representing a URI component and encodes it by replacing special characters with percent-encoded sequences. This is essential for safely passing data in URLs.
🌐
freeCodeCamp
freecodecamp.org › news › javascript-url-encode-example-how-to-use-encodeuricomponent-and-encodeuri
JavaScript URL Encode Example – How to Use ...
August 4, 2020 - When accepting query parameters that may have reserved characters. ```JS let params = encodeURIComponent('mango & pineapple') let url = "http://mysite.com/?search=" + params; //http://mysite.com/?search=mango & pineapple
🌐
phpGrid
phpgrid.com › home › when to use encodeuri() and encodeuricomponent()?
When to use encodeURI() and encodeURIComponent()? | phpGrid - PHP Datagrid
March 25, 2022 - encodeURIComponent() and encodeURI() are native javascript utility functions encodes a URI that replaces URL reserved characters with their UTF-8 encoding.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › difference-between-encodeuri-and-encodeuricomponent-in-javascript
Difference Between encodeURI and encodeURIComponent in JavaScript - GeeksforGeeks
August 5, 2025 - In summary, encodeURI is used for encoding an entire URI while preserving characters that have special meanings in the URI. In contrast, encodeURIComponent is used for encoding individual components of the URI, encoding all special characters.
🌐
LinkedIn
linkedin.com › pulse › encodeuricomponent-encodeuri-javascript-parathan-thiyagalingam-kr8sc
encodeURIComponent & encodeURI in JavaScript
October 29, 2023 - encodeURIComponent and encodeURI are two JS functions used for encoding components of a URI (Uniform Resource Identifier).
🌐
Stack Abuse
stackabuse.com › bytes › javascripts-encodeuricomponent-function
JavaScript's encodeURIComponent() Function
July 31, 2023 - In the code snippet above, you'll see the encodeURIComponent() function in action, transforming the given URI string into an encoded version.
🌐
W3Resource
w3resource.com › javascript › functions › encodeURIComponent-function.php
JavaScript encodeURIComponent functions - w3resource
August 19, 2022 - The encodeURIComponent function is used to encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two or three escape sequences representing the UTF-8 encoding of the character. ...
🌐
Edgecompute
js-compute-reference-docs.edgecompute.app › encodeuricomponent
encodeURIComponent | @fastly/js-compute
The encodeURIComponent() function encodes a URI by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two surrogate characters).
🌐
Medium
ashishdev48.medium.com › encode-and-decode-uri-in-javascript-a-complete-guide-976f4986f6cf
Encode and Decode URI in JavaScript: A Complete Guide | by Ashishkumarjena | Medium
June 17, 2026 - Here, encodeURIComponent() replaces =, &, and spaces with encoded equivalents, making it ideal for safely passing single parameters.
🌐
Reddit
reddit.com › r/golang › javascript's equivalent of encodeuricomponent() method in golang
r/golang on Reddit: JavaScript's equivalent of encodeURIComponent() method in golang
February 24, 2019 -

I have searched enough around the internet. But couldn't find a simple way to do the URL encoding.

In JavaScript we have a function called encodeURIComponent() which is very simple enough to use. But golang has ways to do the conversion. But it's not that simple.

Post your thoughts here, if you could help me out.

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › encodeURI
encodeURI() - JavaScript | MDN
encodeURI, as the name implies, is used to encode a URL as a whole, assuming it is already well-formed. If you want to dynamically assemble string values into a URL, you probably want to use encodeURIComponent() on each dynamic segment instead, to avoid URL syntax characters in unwanted places.
🌐
Reddit
reddit.com › r/nextjs › using encodeuricomponent and decodeuricomponent
r/nextjs on Reddit: Using encodeURIComponent and decodeURIComponent
February 3, 2024 -

Usually, when I create a url for the fetch function I would use encodeURIComponent and on the backend decodeURIComponent on all params I receive. However, I noticed that this makes virtually no difference, as the params I receive on the backend always seem to be decoded. I noticed this because I thought that it would be convenient to write a middleware that does this but apparently this is already handled somehow. The thing is, I don't want to rely on features like this if I don't know where they are coming from and whether or not this behaviour is guaranteed. Do I need to use encodeURIComponent/decodeURIComponent? Where does it say so? I couldn't find anything on the docs about this. Maybe this doesn't even have anything to do with Next, idk

🌐
Reintech
reintech.io › blog › working-with-the-encodeuricomponent-method-as-javascript-contract-developer
Working with the encodeURIComponent() Method
February 22, 2023 - The encodeURIComponent() method is a fundamental JavaScript utility for safely encoding URI components.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › decodeURIComponent
decodeURIComponent() - JavaScript | MDN
decodeURIComponent() uses the same decoding algorithm as described in decodeURI(). It decodes all escape sequences, including those that are not created by encodeURIComponent, like -.!~*'(). js · decodeURIComponent("JavaScript_шеллы"); // "JavaScript_шеллы" js ·
🌐
Make Community
community.make.com › questions
encodeURIComponent and decodeURIComponent - Questions - Make Community
February 19, 2024 - I’m send json through a webform where the values are encoded using Javascript’s encodeURIComponent, to prevent errors in the json file for special characters etc. How can I decode this now in Make.com?