How to properly encode a URL in JavaScript? encodeURI vs encodeURIComponent
Hello everyone! I'm a beginner in JavaScript and ran into a problem when working with URLs. I need to send a request to a server with parameters that contain special characters and Cyrillic. For example, I have a search string: "кофе & чай / рецепты?".\n\nI tried using `encodeURI()`, but noticed that some characters are not encoded. Then I found `encodeURIComponent()`, but now I don't understand which method to use when.\n\nHere's an example of my code that doesn't work as expected:\n\n```javascript\nconst baseUrl = "https://api.example.com/search";\nconst query = "кофе & чай / рецепты?";\nconst fullUrl = baseUrl + "?q=" + encodeURI(query);\nconsole.log(fullUrl);\n// Result: https://api.example.com/search?q=%D0%BA%D0%BE%D1%84%D0%B5%20&%20%D1%87%D0%B0%D0%B9%20/%20%D1%80%D0%B5%D1%86%D0%B5%D0%BF