JavaScript Questions & Answers – Client-Side Storage

This set of Javascript Multiple Choice Questions & Answers (MCQs) focuses on “Client-Side Storage”.

1. Which is not a form of client-side storage?
a) Web Databases
b) FileSystem API
c) Offline Web Applications
d) Online Web Applications
View Answer

Answer: d
Explanation: Client-side storage allows the creater to store data on the users system for faster loading of the website. The various forms of client-side storage are web databases, filesystem API, Offline web applications and cookies.

2. Which is the storage that allows the caching of web pages and their associated resources?
a) Web Databases
b) FileSystem API
c) Offline Web Applications
d) Cookies
View Answer

Answer: c
Explanation: HTML5 defines an “Offline Web Applications” API that allows the caching of web pages and their associated resources (scripts, CSS files, images, and so on). This is client-side storage for web applications themselves rather than just their data, and it allows web apps to install themselves so that they are available even when there is no connection to the Internet.

3. Which is Microsoft’s own proprietary client-side storage?
a) IE User Data
b) Offline Web Applications
c) Cookies
d) Offline Apis
View Answer

Answer: a
Explanation: Microsoft implements its own proprietary client-side storage mechanism, known as “userData,” in IE5 and later. userData enables the storage of medium amounts of string data and can be used as an alternative to Web Storage in versions of IE before IE8. This makes loading of programs and software faster.
advertisement
advertisement

4. Which object supports Filesystem API?
a) Element
b) File
c) Window
d) DOM
View Answer

Answer: b
Explanation: These objects can be obtained from the filesystem property on any file system entry. Some browsers offer additional APIs to create and manage file systems, such as Chrome’s requestFileSystem() method.

5. Which is the most appropriate database for developers requiring a huge amount of data?
a) Database
b) Datawarehouse
c) Web databases
d) Access
View Answer

Answer: c
Explanation: Developers who need to work with really huge amounts of data like to use databases, and the most recent browsers have started to integrate client-side database functionality into their browsers. Client data base helps in making the website faster and handling the data easier.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. The localStorage and sessionStorage belongs to ___________
a) Window object
b) Element object
c) Hash object
d) DOM object
View Answer

Answer: a
Explanation: Browsers that implement the “Web Storage” draft specification define two properties on the Window object: localStorage and sessionStorage. Local storage and Session storage are the web storage objects. Session storage is destroyed once the user closes the browser whereas, Local storage stores data with no expiration date.

7. What is the main difference between localStorage and sessionStorage?
a) Lifetime
b) Scope
c) Both Lifetime and Scope
d) Storage Location
View Answer

Answer: c
Explanation: The difference between localStorage and sessionStorage has to do with lifetime and scope: how long the data is saved for and who the data is accessible to. Session storage is destroyed once the user closes the browser whereas, Local storage stores data with no expiration date.
advertisement

8. What is the lifetime of the data stored through localStorage?
a) Permanent
b) Temporary
c) Both Permanent and Temporary at times
d) Cannot store
View Answer

Answer: a
Explanation: Data stored through localStorage is permanent. it does not expire and remains stored on the user’s computer until a web app deletes it or the user asks the browser (through some browser-specific UI) to delete it. This data is stored on the client side server and is used for faster access of data.

9. Which is the function used to retrieve a value?
a) get()
b) retrieve()
c) getItem()
d) retrieveItem()
View Answer

Answer: c
Explanation: To retrieve a value, pass the name to getItem(). The getItem() method of the Storage interface, when passed a key name, will return that key’s value, or null if the key does not exist, in the given Storage object.
advertisement

10. Which is the function used to store a value?
a) setItem()
b) set()
c) storeItem()
d) store()
View Answer

Answer: a
Explanation: To store a value, pass the name and value to setItem(). The setItem() method of the Storage interface, when passed a key name and value, will add that key to the given Storage object, or update that key’s value if it already exists.

11. What will be the output of the following JavaScript code?

<p id="demo"></p>
<script>
var carName = "Volvo";
var carName;
document.getElementById("demo").innerHTML = carName;
</script>

a) Error
b) Undefined
c) Volvo
d) Garbage value
View Answer

Answer: c
Explanation: A variable does not lose its value if it is re-declared. The Javascript variable will store the value and the output will be Volvo.

12. What will be the output of the following JavaScript code?

<p>The result of adding "5" + 2 + 3:</p>
<p id="demo"></p>
<script>
x = "5" + 2 + 3;
document.getElementById("demo").innerHTML = x;
</script>

a) 523
b) 10
c) 5
d) Error
View Answer

Answer: a
Explanation: When a string and integer is added in Javascript then the resulting output is string. Javascript will type caste integer to string and would then concatenate to produce the output.

13. What will be the output of the following JavaScript code?

<p id="demo">code</p>
<script>
function myFunction() 
{
   var text = document.getElementById("demo").innerHTML;
   document.getElementById("demo").innerHTML = text.toUpperCase();
}
</script>

a) Code
b) CODE
c) code
d) Error
View Answer

Answer: b
Explanation: toUpperCase function is present in the string Library of Javascript. It converts the string to uppercase.

14. What will be the output of the following JavaScript code?

<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = Number(true); 
</script>

a) 1
b) 0
c) true
d) undefined
View Answer

Answer: a
Explanation: The Number() method converts variables to numbers. True value is converted to 1 and a false value is converted to 0.

15. What will be the output of the following JavaScript code?

<p id="demo2"></p>
<script>
Var arr = ["one", "two", "three",];
arr.shift();
document.getElementById("demo2").innerHTML = arr;
</script>

a) two three
b) one two
c) one three
d) error
View Answer

Answer: a
Explanation: The shift() method removes the first element of an array. It “shifts” all other elements to the left.

Sanfoundry Global Education & Learning Series – Javascript Programming.

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.