A URL is short for Uniform Resource Locator, used to identify the location of a resource on the internet.
The format of a URL is scheme:[//authority]path[?query][#fragment], where authority = [userinfo@]host[:port].
scheme - Indicates the protocol, such as http or ftp, requireduserinfo - User information for authentication, formatted as username:password, optionalhost - The host, can be a domain name or IP, requiredport - Port number, optional, defaults to the protocol's standard portpath - Path, used to represent the directory and file address on the host. Optionalquery - Query parameters. Optionalfragment - Fragment, refers to a segment of a network resource. OptionalAn example of a simple URL: https://www.codeeeee.com, using only scheme and host, with the default port for https being 443
URI stands for Uniform Resource Identifier, a short name for identifying a resource on the internet. URL and URI have the same format and are conceptually similar, sometimes interchangeable. The difference between URL and URI is, the former represents the location of a resource, while the latter represents the name of a resource. URL is a type of URI.
URLs can only contain characters from the ASCII set, so encoding is needed when characters outside this set appear. Also, some reserved characters in URLs, like :, /, &, need encoding to avoid confusion in URL parsing.
When encoding URLs, characters are represented by corresponding percent encodings (%). The specific rules for URL encoding can be referenced here
In Javascript, encodeURIComponent and decodeURIComponent can be used for encoding and decoding URLs.