Wednesday, February 1, 2023

Angular / angular





ngAngular





 














































































































































































































































































































































this.newFramework = ""; // empty string
if (this.newFramework) 
{
                                                                console.log("This will not be logged.");
}
- **If `this.newFramework` is null, undefined, an empty string, 0, or NaN**: The condition evaluates to `false`, and the code inside the `if` block is not executed. - **If `this.newFramework` is a non-empty string, a non-zero number, an object, or any other truthy value**: The condition evaluates to `true`, and the code inside the `if` block is executed.

- **`localStorage` does not automatically clear its contents when the browser is closed.
** Data persists until explicitly removed. - If you want data to be cleared when the browser or tab is closed, use **`sessionStorage`**, which only retains data for the duration of the session

// Storing a value
localStorage.setItem('username', 'john_doe');

// Retrieving a value
const username = localStorage.getItem('username');
console.log(username); // Output: john_doe

// Removing a value
localStorage.removeItem('username');

// Trying to retrieve the value again
const removedUsername = localStorage.getItem('username');
console.log(removedUsername); // Output: null

Friday, January 27, 2023

Java Script

Output 




 

 


Anonymous fuction


Arrow Function
-----------------------------------------------------------------------------------------------------------------------------




Call Back Function used for event declaration in JS
https://www.youtube.com/watch?v=qtfi4-8dj9c&t=89s

------------------------------------------------------------

Promises 

Promises are used to handle asynchronous operations in JavaScript. They are easy to manage when dealing with multiple asynchronous operations where callbacks can create callback hell leading to unmanageable code.

What is a promise

A promise is an object that may produce a single value some time in the future with either a resolved value or a reason that it’s not resolved(for example, network error). It will be in one of the 3 possible states: fulfilled, rejected, or pending.

Why do you need a promise

  1. Promises are used to handle asynchronous operations. They provide an alternative approach for callbacks by reducing the callback hell and writing the cleaner code.

What are the three states of promise

  1. Promises have three states:

    1. Pending: This is an initial state of the Promise before an operation begins
    2. Fulfilled: This state indicates that the specified operation was completed.
    3. Rejected: This state indicates that the operation did not complete. In this case an error value will be thrown.

Definition : Callback

JavaScript callback is a function which is to be executed after another function has finished execution.

Need of Callback Functions

We need callback functions because many JavaScript actions are asynchronous, which means they don't really stop the program (or a function) from running until they're completed, as you're probably used to. Instead, it will execute in the background while the rest of the code runs.














 

Important

 https://www.youtube.com/watch?v=NWLyoCYEe0A