Asynchronous Programming - Reading Assignment

  1. Synchronous does everything in the same order as they arrive. And on the other hand, asynchronous can pause one task to continue with another.

  2. Callback hell is multiple functions being nested inside one another to the point of it looking and running in a complex and confusing manner.

  3. In JQuery we can use promises to chain callbacks and deal with errors

1 Like
  1. What is the difference between synchronous and asynchronous functions?
    Synchronous is where a function is executes 1 at a time.

Asynchronous is the functionality where a function can be started and then returned to whilst something else is processed.

  1. What is callback hell?
    Call back hell is where an operation requires several nested functions.

  2. Which technique can help us solve callback hell?
    This can be dealt with by using promises which is built into jQuery.

1 Like
  1. What is the difference between synchronous and asynchronous functions?

In the synchronous functions while each operation is being processed, nothing else can happen. This means that JavaScript is single threaded. Only one thing can happen at a time, on a single main thread, and everything else is blocked until an operation completes.

Asynchronous functions allow us to write a synchronous promise based code in a synchronous manner. The code is still asynchronous but we can now read it in a synchronous manner. So you can do more than one thing at a time.

  1. What is callback hell?

JavaScript has an asynchronous model. Whenever an asynchronous action is completed, you often want to execute some code afterwards. First callbacks were often used to solve this problem. However, when programming code with multiple asynchronous elements a problem arises using callbacks. Because when you nest multiple callbacks inside each other the code becomes hard to maintain very fast. This anti-pattern is called callback hell.

  1. Which technique can help us solve callback hell?

The technique is Promises. Promises solved many of the issues that appeared in nested callbacks. A key property of promises are that they can be nicely chained together using a promise chain. This allows for much cleaner syntax than callbacks and easier error handling.

1 Like
  1. Synchronous functions are “blocking” functions that prevent sequential code events from occurring until the active event is complete. Asynchronous functions allow for sequential code events to occur while previous tasks are being completed.
  2. Callback hell is the un-layering of complicated multi-nested function returns.
  3. In jQuery, “promises” can be utilized to chain callbacks and track errors. In Node.js, the runtime can be extended to make asynchronous code seem synchronous.
1 Like

1. What is the difference between synchronous and asynchronous functions?
Synchronous functions can block any additional functions until they finish.
Asynchronous functions can be set aside, so to speak, while they await a response.
2. What is callback hell?
Having a series of nested functions which rely on each other to complete a task.
3. Which technique can help us solve callback hell?
Promise in jQuery helps us chain callback hell and deal with errors.

1 Like
  1. Synchronous functions are functions that are ran till complete and asynchronous functions can be ran then set to the side and continue the program without having to ficus on completing it.

  2. Programs can get complex and could have sub-levels of callbacks upon callback.

3.Promises are used to solve callback helll with allows us to chain callbacks and to deal with errors.

1 Like
  1. Synchronous task are executed right away while asynchronous functions can be initiated and then put aside until need it.
  2. IT is when there are nested events. This happens in asynchronous functions.
  3. Using promises.
1 Like
  1. What is the difference between synchronous and asynchronous functions? synchronous task will occupy Javes continuously until its completion, an asynchronous task can be initiated and then put aside until a later date while our valet gets started on the next task on his to-do list.
  2. ***What is callback hell?***So you can imagine that more complex operations tend to produce even more levels and sub-levels, which is what is poetically known as callback hell
  3. ***Which technique can help us solve callback hell?***e promises
1 Like
  1. A synchronous function is a normal function that runs sequentially in JS. If it starts, then the next function will not run until the previous function stopped running. Asynchronous can start and while it is waiting for a response, it allows other functions to run before it finishes

  2. When you have multiple callbacks nested within one function and it is difficult to figure out the order of execution

  3. Promises can help us chain callbacks and make the code less messy

1 Like

1. What is the difference between synchronous and asynchronous functions?
synchronous: Can only do one task at a time.
asynchronous: you can use event loop in the background, meaning that it can do two things,
send a request and schedule the second handler to run when the request comes back.
2. What is callback hell?
when a operation requires levels and sublevels of nested callback functions
3. Which technique can help us solve callback hell?
Promise, a JQuery library.

1 Like
  1. Synchronous functions can be done one at a time in particular order , while asynchronous functions can be procrastinated.

  2. Callback hell is when we use too many nested asynchronous functions and callbacks and the code becomes hard to read and use .

  3. We can solve the callback hell by using Promises or by making the asynchronous code ‘look’ synchronous.

1 Like

1.)
Synchronous tasks are started and followed until completion
Asynchronous tasks are started and then put aside
2.)
If a Operation has multiple levels. Nested function as example.
3.)
in JQuery: Using promises → kets us chain Callbacks
in Node.js: Extending runtime to create code that looks synchronous

1 Like

1)Synchronous functions run sequentially, the next function starts when the previous one ends.
Asynchronous functions can run the next function while waiting for the first one to complete the task.
2)when a specific operation requires multiple levels of nested callback functions
3)Promises, a built-in jQuery library

1 Like
  1. What is the difference between synchronous and asynchronous functions?
  • Synchronous functions lock up the browser and asynchronous functions do not.
  1. What is callback hell?
  • More complex operations that tend to produce even more levels and sub-levels; This is what is
    poetically known as callback hell.
  1. Which technique can help us solve callback hell?
  • Promises: jQuery ships with a simple built-in promise library that enables us to chain callbacks and deal with errors.
1 Like

@Malik , thanks a lot. Here the code

<html>
  <head>
    <title> Interactive website </title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  </head>

  <body>
    <h1>My Favorite Fruits</h1>
    <ol id ="fruitlist">
     </ol>
     <input id ="fruitTexInput" placeholder="Write fruit" type = "text"/>
     <button id = "addFruitButton"> Add fruit</button>

    <script>


    var  fruits =["Apple", "Orange", "Banana" ,"Pineapple"];

    function redrawList(){
      var list = $("#fruitList");
      list.html("");

    $.each(fruits,function(index,value){

    $("<li/>").text(value).apendTo(list);

    });
    }
    redrawList();
    
     $("#addFruitButton").click(function(){
       var fruitText = $("#fruitTexInput").val();
     fruits.push(fruitText);
     console.log(fruits);

     redrawList();
  });

    </script>



  </body>
1 Like
  1. What is the difference between synchronous and asynchronous functions?
    Event handlers can begin asynchronous functions and put them aside for later completion, while synchronous functions must be completed at once.
  2. What is callback hell?
    Complex operations in javascript that require multiple nested functions
  3. Which technique can help us solve callback hell?
    Use “promises” that chain callbacks and help minimize errors
1 Like

Hi @Emmaculate,

This is a simple mistake in your code. Your Ids do not match.

Notice the capital and small case L in your id names. Fixing this will solve your issue :slight_smile:

Happy learning!

1 Like

Thanks so much, I just made the correction but the code still did not run. Still the same error message as before …

I ran your code and it worked with the change.

Refresh your browser after you made the changes so that it reflects on the browser.

1 Like

Oh,okay!
I’m running to go give it a try😄
Thanks once more :pray:t5:

1 Like