javascript-local-storage Flashcards
1
Q
How do you store data in localStorage?
A
To store data in localStorage use: localStorage.setItem(‘name’, stringified data variable);
2
Q
How do you retrieve data from localStorage?
A
To retrieve data from localStorage use: localStorage.getItem(string name);
3
Q
What data type can localStorage save in the browser?
A
The data type that localStorage can save in the browser is a string.
4
Q
When does the ‘beforeunload’ event fire on the window object?
A
The ‘beforeunload’ event fires right before the page closes or refreshes, while everything is still loaded into the browser and document. The preventDefault() method will have the website ask the user if it is okay to leave the page.