This set of HTML Multiple Choice Questions & Answers (MCQs) focuses on “Web Storage”.
1. Before HTML5 where data had to be stored?
c) only in Internet Explorer
d) only in Chrome
Explanation: When HTML5 was not introduced application data had to store in cookies when server requested for it. Web storage was secure then as well as large data could be stored even it does not affect performance. After coming of HTML5 web applications can store data within the browser that the user is using.
2. In localStorage object data ________
a) is deleted after the browser has been closed
b) is not deleted after the browser has been closed
c) can be seen but can not edit
d) can be seen as well as edit
Explanation: Data with no expiration date is stored by localStorage object. Here the data is not deleted if we close the browser. We can have data at the next day or week or year. Syntax is
localStorage(“firstname”,”Tanya”); document.getElementById(“fo”).innerHTML= localStorage.getItem(“firstname”); here fo is id.
3. In sessionStorage object data __________
a) is not deleted after the browser has been closed
b) can be seen but can’t edit
c) can be seen as well as edit
d) is deleted after the browser has been closed
Explanation: sessionStorage object works same as localStorage object except the data is stored for one session only. When the use closes the browser the data is deleted. Syntax is
sessionStorage.firstname-“Tanya”; document.getElementById(“fo”).innerHTML= sessionStorage.firstname;
4. What is the limit of character storage for chrome 23.0 in localStorage?
c) 1021 k
d) 4.98 M
Explanation: We can’t store any character in localStorage in chrome 23.0, for chrome 18.0 it is unlimited i.e. can store any number of characters, for chrome 19.77 it is 1021 k, for chrome 22.0 it is 2.49 M, for chrome 24.0, 25.0, 27.0 it is 2.49 M, for chrome 28.0, 30.0, 31.0 and 31.1 it is 4.98 M.
5. What is the limit of character storage for chrome 23.0 in sessionStorage?
a) 510 k
c) 1021 k
d) 2.49 M
Explanation: We can store 510 k characters in sessionStorage in chrome 23.0, for chrome 18.0 and chrome 24.0 we can store unlimited characters, for chrome 19.77 its value is 1021 k, for chrome 25.0 and 27.0 it is 2.49 M, for chrome 28.0, 30.0, 31.0, 31.1 its value is 4.98 M.
6. Which of the following is not a web storage interface?
Explanation: There is only three web storage interface window, storage, and StorageEvent. Window object provides access to the local storage objects. Storage retrieves, set and remove data from the domain. Storage event is fired when the storage area on a document’s window changes.
7. Which of the following returns a number of value pairs?
Explanation: storage.length returns number of value pairs that are currently present in the list, storage.key(n) returns name of nth key from the list, storagesetItem(key,value) sets the value which is identified by key to value, storage.clear() empties the list which is associated with values.
8. Which of the following is invoked when it is not fired on window object?
Explanation: When removeItem(), clear() and setItem() are invoked the events are fired on window object, which accesses newly stored or removed data, as defined by LocalStorage and sessionStorage attributes, getItem(key) method returns the current value associated with the key.
9. Which of the following is not the storageEvent interface?
Explanation: There are many storgeEvent interfaces like event.key, event.newValue, event.url, event.oldValue, event.storageArea. Event.key returns the key if the storage item is changed, event.oldValue and event.newValue returns old value and the new value of the key whose value has been changed. Event.url returns the URL of a document which has been changed.
10. For clearing all the settings which function should be called?
Explanation: If we want to delete all the setting we can call localStorage.clear() method, localStorage.remove(key) only removes the key of the value that we have given. Same can be applied with sessionStorage also the syntax will be sessionStorage.clear().
Sanfoundry Global Education & Learning Series – HTML.
To practice all areas of HTML, here is complete set of 1000+ Multiple Choice Questions and Answers.