Difference Between Local Storage and Session Storage

Local Storage: This read-only interface property provides access to the Document’s local storage object, the stored data is stored across browser sessions. Similar to sessionStorage, except that localStorage data gets cleared when the page session ends – that is when the page is closed. It is cleared when the last “private” tab of a browser is closed (localStorage data for a document loaded in a private browsing or incognito session).

Session Storage: Session Storage objects can be accessed using the sessionStorage read-only property. The difference between sessionStorage and localStorage is that localStorage data does not expire, whereas sessionStorage data is cleared when the page session ends. A unique page session gets created once a document is loaded in a browser tab. Page sessions are valid for only one tab at a time. Pages are only saved for the amount of time that the tab or the browser is open; they do not persist after the page reloads and restores. A new session is created each time a tab or window is opened; this is different from session cookies.

Difference Between Global Scope & Block Scope

Block Scope: Before ES6 (2015), JavaScript had only Global Scope and Function Scope. ES6 introduced two important new JavaScript keywords: let and const. These two keywords provide Block Scope in JavaScript. Variables declared with the var keyword can NOT have block scope. Variables declared inside a { } block can be accessed from outside the block.

Local Scope: Variables declared within a JavaScript function, become LOCAL to the function. Since local variables are only recognized inside their functions, variables with the same name can be used in different functions. Local variables are created when a function starts, and deleted when the function is completed.

Event Loop in JavaScript

JavaScript has a runtime model based on an event loop, which is responsible for executing the code, collecting and processing events, and executing queued sub-tasks. This model is quite different from models in other languages like C and Java. Note that the arguments and local variables may continue to exist, as they are stored outside the stack — so they can be accessed by any nested functions long after their outer function has returned.

Runtime concepts: The following sections explain a theoretical model. Modern JavaScript engines implement and heavily optimize the described semantics.

Different ways to get Undefined value in JavaScript.

There are generaly 8 ways to get Undefined value in JavaScript. These ways are mentioned bellow:

1. Declaring a variable with no value: For Example, If we declare variable like this 'let first'. And then try to access the value of first. We will get an Undefined value.

2. Function with no Return value: When a function does not return any value and we try to store a value by that function we will get an Undefined.

3. Parameter that has not passed: If function has parameter but in the function argument we do not pass any value thar gives an Undefined

4. Property that does not exist: If we try to read any propety that does not exit than we get an Undefined.

5. Access an Array element outside of the index range: When we try to access an array element from outside the index range that gives an undefind.

6. If there are no return value: When JavaScript don't know what to return that will give us undefind.

7. Deleting an Element inside an array and returning it: When JavaScript delete an element inside an array and returning it that give an undefind.

8. Set a value directly to Undefined: This one is quite self explained.