encodeURI encodes a complete URL while preserving reserved structural characters, whereas encodeURIComponent encodes a single component and escapes those structural characters too.
As documented by MDN Web Docs, encodeURI leaves :, /, ?, #, &, and = intact so a whole address stays functional, making it right for full URLs. encodeURIComponent escapes everything except the RFC 3986 unreserved set, so it is the correct choice for query-parameter values, path segments, or fragment text that might contain reserved characters.
Using encodeURI where encodeURIComponent is needed is a common bug: an unencoded & inside a value will be misread as a parameter separator, silently corrupting the request.