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.














 

Comments

Popular posts from this blog

Travel RESUME CV

Tablig