MERN Stack Interview Questions & Answer Series Part 12

Posted on August 21, 2023 By

MERN stands for MongoDB, Express, React, Node, after the four key technologies that make up the stack. MERN Stack Interview Part 12 Javascript Questions.

Q111. What is scope in javascript?
Scope is the accessibility of variables, functions, and objects in some particular part of your code during runtime.

Q112. What is a service worker?
A Service worker is basically a JavaScript file that runs in the background, separate from a web page & provides features that don’t need a web page or user interaction. Some of the major features of service workers are Rich offline experiences, periodic background syncs, push notifications and programmatically managing a cache of responses.

Q113. How do you manipulate DOM using a service worker?
Service worker can’t access the DOM directly. But it can communicate with the pages it controls by responding to messages sent via the postMessage interface, and those pages can manipulate the DOM.

Q114. What is web storage?
Web storage is an API that provides a mechanism by which browsers can store key/value pairs locally within the user’s browser, in a much more intuitive fashion than using cookies. The web storage provides two mechanisms for storing data on the client.

Local storage: It stores data for current origin with no expiration date.
Session storage: It stores data for one session and the data is lost when the browser tab is closed.

Q115. What is IndexedDB?
IndexedDB is a low-level API for client-side storage of larger amounts of structured data, including files/blobs. This API uses indexes to enable high-performance searches of this data.

Q.116 What are the methods available on session storage?
The session storage provided methods for reading, writing and clearing the session data.
– Save data to sessionStorage sessionStorage.setItem(‘key’, ‘value’);
– Get saved data from sessionStorage let data = sessionStorage.getItem(“key”);
– Remove saved data from sessionStorage sessionStorage.removeltem(“key”);
– Remove all saved data from sessionStorage sessionStorage.clear();

Q.117 What is a Cookie?
A cookie is a piece of data that is stored on your computer to be accessed by your browser. Cookies are saved as key/value pairs.

Q.118 Why do you need a Cookie?
Cookies are used to remember information about the user profile. When a user visits a web page, the user profile can be stored in a cookie and when next time the user visits the page again, thecookie remembers the user profile.

Q.119 How do you access web storage?
The Window object implements the WindowLocalStorage and WindowSessionStorage objects which has localStorage and sessionStorage properties respectively. These properties create an instance of the Storage object, through which data items can be set, retrieved and removed for a specific domain and storage type (session or local).

Q120. What is a storage event and its event handler?
The StorageEvent is an event that fires when a storage area has been changed in the context of another document. Whereas onstorage property is an EventHandler for processing storage events.
Example:

window.onstorage = function(e) { console.log('The' + e.key + "key has been changed from + e.oldValue + 'to' + e.newValue + '.');}

MERN Stack Interview Part 12. MERN Stack Interview MongoDB Express React Node Javascript.


Leave a Reply

Your email address will not be published. Required fields are marked *