1. What is the Difference Between Local Storage and Session Storage?
“The Storage interface of the Web Storage API provides access to a particular domain's session or local storage. It allows, for example, the addition, modification, or deletion of stored data items.”
LocalStorage persists the storage across browser sessions. So even if the domain is opened in a new tab, or the browser is closed and reopened, the storage is saved. There is no expiration.
SessionStorage is cleared when the page session ends. A page session lasts as long as the tab or the browser is open. Therefore, when you open a new tab or a new window, this creates a new session and new storage.
2. Difference Between Global Scope and Block Scope.
In a browser environment, the global scope is controlled by the window object while in Node. js, it's controlled by the global object.
Block scopes are what you get when you use if statements, for statements, and the like.
3. How to work Event Loop in Javascript?
The Event Loop has one simple job — to monitor the Call Stack and the Callback Queue. If the Call Stack is empty, the Event Loop will take the first event from the queue and will push it to the Call Stack, which effectively runs it.
Such an iteration is called a tick in the Event Loop. Each event is just a function callback.
4. How to get an Undefined Value in Javascript?
Undefined is also a primitive value in JavaScript. A variable or an object has an undefined value when no value is assigned before using it. So you can say that undefined means lack of value or unknown value.
You will get undefined value when you call a non-existent property or method of an object.
An undefined evaluates to false when used in conditional expression.
- Undefined are primitive values in JavaScript
- An undefined value means lack of value.
- An undefined value evalutes to false in conditional expression.