HTML Questions & Answers – Web Storage

This set of HTML Multiple Choice Questions & Answers (MCQs) focuses on “Web Storage”.

1. Before HTML5 where data had to be stored?
a) cookies
b) browser
c) only in Internet Explorer
d) only in Chrome
View Answer

Answer: a
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
View Answer

Answer: b
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
View Answer

Answer: d
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

advertisement
advertisement
sessionStorage.firstname-“Tanya”; document.getElementById(“fo”).innerHTML= sessionStorage.firstname;

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

4. What is the limit of character storage for chrome 23.0 in localStorage?
a) unlimited
b) none
c) 1021 k
d) 4.98 M
View Answer

Answer: b
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.
advertisement

5. What is the limit of character storage for chrome 23.0 in sessionStorage?
a) 510 k
b) unlimited
c) 1021 k
d) 2.49 M
View Answer

Answer: a
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?
a) storage
b) window
c) storageEvent
d) privacy
View Answer

Answer: d
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.
advertisement

7. Which of the following returns a number of value pairs?
a) storage.key(n)
b) storage.length
c) storage.setItem(key,value)
d) storage.clear()
View Answer

Answer: b
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?
a) removeItem()
b) clear()
c) setItem()
d) getItem()
View Answer

Answer: d
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?
a) event.newValue
b) event.url
c) event.key
d) event.clear
View Answer

Answer: d
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?
a) localStorage.remove(key)
b) localStorage.clear()
c) localStorage.remove()
d) localStorage.clearAll()
View Answer

Answer: b
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.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.