Created
July 5, 2019 01:12
-
-
Save luisenriquecorona/0e94285312b77c875a33196cfe9bca47 to your computer and use it in GitHub Desktop.
Storage lifetime and scope are explained in more detail below. First, however, let’s look at some examples. The following code uses localStorage, but it would also work with sessionStorage:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var name = localStorage.username; // Query a stored value. | |
name = localStorage["username"]; // Array notation equivalent | |
if (!name) { | |
name = prompt("What is your name?"); // Ask the user a question. | |
localStorage.username = name; // Store the user's response. | |
} | |
// Iterate through all stored name/value pairs | |
for(var name in localStorage) { // Iterate all stored names | |
var value = localStorage[name]; // Look up the value of each one | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment