MERN stands for MongoDB, Express, React, Node, after the four key technologies that make up the stack. MERN Stack Interview Part 13 Javascript Questions.
Q121. Why do you need web storage?
Web storage is more secure, and large amounts of data can be stored locally, without affecting website performance. Also, the information is never transferred to the server. Hence this is a more recommended approach than Cookies.
Q122. How do you check web storage browser support?
You need to check browser support for localStorage and sessionStorage before using web storage.
if (typeof(Storage) !== "undefined"){ // Code for localStorage/sessionStorage } else {
// Sorry! No Web Storage support
}
Q123. What are the restrictions of web workers on DOM?
WebWorkers don’t have access to below javascript objects since they are defined in an external files
– Window object
– Document object
– Parent object
Q124. What is a promise?
A promise is an object that may produce a single value some time in the future with either a resolved value or a reason that it’s not resolved (for example, network error). It will be in one of the 3 possible states: fulfilled, rejected, or pending.
The usage of a promise would be as below:
const promise = new Promise(resolve => { setTimeout(() => { resolve("I'm a Promise!"); }, 5000); }, reject => {promise.then(value => console.log(value));}
Q125. Why do you need a promise?
Promises are used to handle asynchronous operations.
They provide an alternative approach for callbacks by reducing the callback hell and writing the cleaner code.
Q126. What is a callback function?
A callback function is a function passed into another function as an argument. This function is invoked inside the outer function to complete an action. Let’s take a simple example of how to use callback function.
function callbackFunction(name) {
console.log('Hello '+ name);
}
function outerFunction(callback){
let name=prompt('Please enter your name.');
callback(name);
}
outerFunction(callbackFunction);
The callbacks are needed because javascript is an event driven language. That means instead of waiting for a response javascript will keep executing while listening for other events.
Q127. What is a callback hell?
Callback Hell is an anti-pattern with multiple nested callbacks which makes code hard to read and debug when dealing with asynchronous logic.
Q128. What are server-sent events?
Server-sent events (SSE) is a server push technology enabling a browser to receive automatic updates from a server via HTTP connection without resorting to polling. These are a one way communications channel – events flow from server to client only. This has been used in Facebook/Twitter updates, stock price updates and news feeds etc.
Q129. What is callback in callback?
You can nest one callback inside in another callback to execute the actions sequentially one by one. This is known as callbacks in callbacks.
Q130. What is promise chaining?
The process of executing a sequence of asynchronous tasks one after another using promises is known as Promise chaining.
MERN Stack Interview Part 13. MERN Stack Interview MongoDB Express React Node Javascript.
Read Also: MERN Stack Interview Questions & Answer Series Part 10