Answer:
Their main difference is that local storage
data does not expire, whereas session storage data gets cleared when
the user closes its browser window.
Page sessions are valid for only one tab at a time. So, if a user has
three tabs open, each one will have its own page session.
Since local storage is not session-based, all the data must be deleted
via javascript or manually
Answer:
Global scope - Global scope contains all of the
things defined outside of all code blocks. A code block simply
consists of grouped statements inside curly braces ({ }). if
statement, loops, function are examples of structure that create a
code block. A global variable has global scope. A global variable is
accessible from anywhere in the code.
Local Scope - Local scope contains things defined
inside code blocks. A local variable has local scope. A local variable
is only accessible where it’s declared.
Answer:
The event loop is the secret behind JavaScript’s asynchronous programming. JS executes all operations on a single thread, but using a few smart data structures, gives us the illusion of multi-threading. The asynchronous behavior is not part of the JavaScript language itself, rather it is built on top of the core JavaScript language in the browser (or the programming environment) and accessed through the browser APIs.
Browser JavaScript execution flow, as well as in Node.js, is based on an event loop. The event loop concept is very simple. There’s an endless loop, where the JavaScript engine waits for tasks, executes them, and then sleeps, waiting for more tasks.
Answer:
The undefined is a primitive type in JavaScript. So the undefined is a type. And the undefined type has exactly one value that is undefined.
JavaScript uses the undefined value in the following situations.
1. Accessing an uninitialized variable. When you declare a variable and don’t initialize it to a value, the variable will have a value of undefined.
2. Accessing a non-existing property of an object If you access a non-existing property of an object, you’ll get undefined.
3. Function parameters When you call a function with a number of parameters, and don’t pass all the arguments, the parameters inside the function becomes undefined.
4. Functions return a value A function that doesn’t have a return statement implicitly returns undefined.
5. Accessing out-of-bounds array elementsWhen you access an array element that is out-of-bounds, you’ll get the undefined value.