What Data Type Is URI?
A URI, which stands for Uniform Resource Identifier, is a string of characters that identifies a resource on the web. It can be used to locate and retrieve information from various sources such as websites, files, or databases. In HTML, URIs are commonly used as values for attributes like href (for hyperlinks) and src (for image sources).
A URI typically consists of several components:
- Scheme: The scheme specifies the protocol or type of resource being identified. Examples include http, https, ftp, mailto.
- Authority: The authority component includes the domain name or IP address of the server hosting the resource.
- Path: The path component represents the location of a specific file or resource on the server.
- Query: The query component allows for passing parameters to a web application or script.
- Fragment: The fragment component identifies a specific portion within a document or webpage.
Data Type of URI
URL object. This object provides various properties and methods for working with URIs, such as accessing individual components, modifying them, or creating new URIs.
Let’s say you have a URI stored in a variable called
const myURI = 'https://www.example.com/path/file.html?param=value#section'; const url = new URL(myURI); console.log(url.protocol); // Output: "https:" console.host); // Output: "www.com" console.pathname); // Output: "/path/file.html" console.search); // Output: "?param=value" console.hash); // Output: "#section"
The above code snippet demonstrates how to create a
URL object from a URI and access its different components using the object’s properties. This allows for easy manipulation and extraction of specific parts of the URI.
A URI is a string of characters used to identify resources on the web. In HTML, it is considered as a string data type and can be manipulated using various string functions or parsed into its individual components using the
Remember: When writing HTML code, always ensure that URIs are properly formatted and escaped to avoid any issues or errors when linking or accessing resources on the web.