LocalStorage is a type of web storage that allows JavaScript websites and apps to store and access data right in the browser with no expiration time.
To use it in JavaScript, you can follow these steps:
1. Setting the item to the localStorage
\`\`\`javascript localStorage.setItem(‘key’, ‘value’); \`\`\` ‘key’ is the name you want to call the data you’ll be saving, while ‘value’ is the actual data you want to store.1. Getting the item from the localStorage
\`\`\`javascript let data = localStorage.getItem(‘key’); \`\`\` When you retrieve data, remember that everything stored in localStorage is stringified. If you’re storing an array or object, you’ll need to parse it when you retrieve it: \`\`\`javascript let data = JSON.parse(localStorage.getItem(‘key’)); \`\`\`1. Removing the item from the localStorage
\`\`\`javascript localStorage.removeItem(‘key’); \`\`\` You use the key name to remove it from storage.1. Clearing all data from the localStorage
\`\`\`javascript localStorage.clear(); \`\`\` This would completely clear the localStorage.Remember that storage is scoped to the domain, so www.example.com and www.sub.example.com can’t access each other’s localStorage.