Thursday, January 23, 2025

code

  • Local Storage: Data stored with no expiration time. The data persists even when the browser is closed and reopened.
    Session Storage: Data that is only available for the duration of the page session. It is cleared when the page session ends, which typically happens when the browser or tab is closed.

    localStorage.setItem('key', 'value');
    sessionStorage.setItem('key', 'value');
    let value = localStorage.getItem('key');
    console.log(value);  // Output: value
    
    let value = sessionStorage.getItem('key');
    console.log(value);  // Output: value
    localStorage.removeItem('key');//To remove an item from local storage:
    sessionStorage.removeItem('key');
    localStorage.clear();//to clear all items from local storage:
    
    sessionStorage.clear();

    ----

  • What it is: Authentication is the process of verifying the identity of a user or entity.
    passwords

  • What it is: Authorization is the process of determining what an authenticated user is allowed to do.
    Purpose: To ensure that the user has permission to access specific resources or perform specific actions.
    Authentication:
     Showing your ticket at the entrance to prove you are a valid attendee.
    Authorization: Accessing different areas of the venue (e.g., general seating, VIP lounge) based on the permissions granted by your ticket.






  •  palindrome

     




    features of react
    Virtual DOM:
    Component-Based Architecture
    JSX (JavaScript XML
    One-Way Data Binding
    State Management
    Lifecycle Methods
    Hooks
    React Router
    Server-Side Rendering (SSR)












    Sunday, January 12, 2025

    js new 1

    hoisting:
    When a JavaScript function is called, several things happen:

    Function Creation Phase:

    Before executing the function, JavaScript creates a scope for the function. During this phase, all variable and function declarations are "hoisted" to the top of their containing function or global scope. This means that variable and function declarations are processed first, but their assignments are not.

    Execution Phase:

    After hoisting, the JavaScript engine begins executing the code line by line.
    What actually happens:
    Hoisting Phase:

    The var i declaration is hoisted to the top of the function x, but the assignment i = 5 remains in its place.

    Hoisted Code: (Conceptual Representation):

    3 Execution Phase:

    The JavaScript engine executes the setTimeout function call, which schedules the console.log(i) to run after 1 second.

    It then assigns 5 to the variable i.

    Because of hoisting, the variable i is known to exist throughout the entire function x. This is why, when the setTimeout callback executes, it can access the value of i and logs 5.

    To summarize: When a function is called, its entire code isn't executed first before starting execution. Instead, variable and function declarations are hoisted to the top of their scope, and then the code is executed line by line. This process ensures that variable i is accessible within the setTimeout callback.