Difference between Session Storage VS Local Storage

Session Storage:
The session storage remains in the browser as long as the browser is open, when the browser is closed the data is removed from the session storage.

  • Capacity: Data store 5Mb
  • Accessible From: Same Tab
  • Expires: On Tab Close
  • Local Storage:
    Local storage maintains data across all instances of a site, whether they're in different tabs or windows. It is also permanent, so the data won't disappear when you close your browser.

  • Capacity: Data store 10Mb
  • Accessible From: Any Window
  • Expires: Naver
  • Difference between Global Scope vs Functional Scope

    Global Scope:
    if we write a variable outside of the function All scripts and functions on a web page can access it

  • Accessible: variables can be accessed from anywhere in a JavaScript program
  • Variables declared Globally (outside any function) have Global Scope.
  • Function Scope:
    If we declare a variable inside a function It can only be accessed from within the function.

  • Accessible: Local variables are created when a function starts, and deleted when the function is completed.
  • JavaScript has function scope: Each function creates a new scope.
  • Variables defined inside a function are not accessible (visible) from outside the function.
  • JavaScript event loop

    When our javascript file is run, it is executed line by line. During the execution, if any asynchronous function is found, then it is put in the queue and the code of the next line is executed, and when all the code execution is finished, the code in the queue is run, thus basically the event loop works. by doing

    probability of getting undefined

    An undefined variable or anything without a value will always return "undefined" in JavaScript. This is not the same as null, despite the fact that both imply an empty state.

    • When a variable is declared or initialized but no value is assigned to it, JavaScript automatically displays "undefined". It looks like this:
    • Array [ ]: Like you have an array you will try access a value that does't exist you will get undefined
    • Object { }: Same of array if you try to get a properties value but it does't exist you will get undefined
    • If you declare a variable and assign undefined you will get result undefined