Asynchronous Programming - Reading Assignment

  1. What is the difference between synchronous and asynchronous functions?
  • Synchronous function can only deal with codes one at a time and cannot execute another until the existing one has been completed.

  • Asynchronous function on the other hand can execute codes without the need of response as it can put it aside and continue working.

  1. What is callback hell?
  • A more complex operations tend to produce even more levels and sub-levels of functions is called a callback hell.
  1. Which technique can help us solve callback hell?
  • Promises on jQuery and by extending the runtime in Node.js
1 Like

problem with #3: even though node.js uses whatever, i still got errors from functions not running one after the other in the TA class… need way more help with callback functions than i realized…

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

Synchronous functions require JavaScript’s full attention, where no other function can be tended to until it’s completed. Whereas, an Asynchronous function can be initiated, and tended to later, so JavaScript can focus on other functions while it waits for the asynchronous function to complete its task.

2. What is callback hell?

Describes an unwieldy number of nested “if” statements or functions. You have multiple functions that are asynchronous.

3. Which technique can help us solve callback hell?

A common way to deal with excessive callbacks in a browser is to use promises. It’s a library that’s built into JQuery that enables us to chain callbacks and deal with errors. In Node.js it’s a bit different. By extending the runtime, we can abstract away the asynchronicity and write code that looks synchronous.

1 Like
  1. What is the difference between synchronous and asynchronous functions?
    A. Synchronous code works in Sequence by every line code work one after another.
    While Asynchronous code allows the program to be executed immediately where the synchronous code will block further execution of the remaining code until it finishes the current one.

  2. What is callback hell?
    A. This is a big issue created by coding with complx nested calls. Here, each and every callback takes an argument that is a result of the previous callbacks. In this manner, The code structure looks like a pyramid, making it difficult to read and maintain. Also, if there is an error in one function, then all other functions get affected.

  3. Which technique can help us solve callback hell?
    A. There are four solutions to callback hell:
    a. Write comments for clarity
    b. Split functions into smaller functions to avoid confusion and make code clean
    c. Using Promises
    d. Using Async/await functions

1 Like

I was 85% done with the old version of the JavaScript Programming course. Now it seems to have disappeared and replace by the 2021 version. Anyway for me to complete what I started?

1 Like

Old version gone. Restart new? Not sure. I have the same experience though you are ahead of me. I was working on chapter 5, jQuery. I only noticed a difference in access yesterday and they have not yet had time to tell me what is next. If there is a replacement version, I don’t mind doing the lessons again. I am new to coding languages. These languages are not only complicated but interlace with each other including the use of symbols… many symbols that have various meanings. If the language does not connect properly, it does not run.
What verbal languages do that? None that I can think of. Translate, yes. Not interface with each other.
When I learned Spanish, it wasn’t German-Spanish. In the state of Texas, USA bilingual can mean the language spoken is “Tex-Mex,” a broken dialog. That is not likely anywhere else.LOL. Some coding languages are compiled programming language, some scripting language, and then libraries. Can be confusing if not well understood. So, many other languages I want to learn once I have a foundation of HTML and JavaScript. I wish you well in your completion to certification.

  1. single threaded, stuck on 1st task till completion vs asynchronous which starts and waits but doesn’t block.
    2- Callback hell is a situation where several functions are being performed in nested form.
    3- Promise is used to solve the call back hell situation. jQuery, AngularJS come with promise library. It also handles errors.
1 Like
  1. Synchronous functions mean that only one code event can run at a time in the function, blocking any further execution of the program until each event is completed in order. Whereas with asynchronous functions more than one section of code can be run at the same time, meaning tasks can begin and be set aside to be completed at a later time, while other new tasks begin.

  2. Callback hell is when you have multiple functions nested within one another, in an increasing complexity of levels and sub-levels, leading to an undesirable situation of callbacks calling callbacks.

  3. Promises are an effective way to deal with callback hell. Promises can chain callbacks and deal with errors. jQuery comes with a built-in promise library. Another solution is extending the runtime and abstracting away the asynchronicity via Node.js.

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

Synchronous is single threaded, which means that only one section if code can be running at any one time. Asynchronous tasks can be initiated and then put aside until a later time while other tasks can be started.

  1. What is callback hell?

With Asynchronous tasks running, callbacks are when you are waiting on answers back from previous tasks. Even very simple actions can create several layers and sub layers of callbacks which gets referred to as callback he’ll.

  1. Which technique can help us solve callback hell?

Promises help to solve this. Jquery ships with a simple built in promise library that enables us to chain callbacks and deal with errors.

In node.js, extending the run time allows us to extract away the asynchronicity and write code that looks synchronous.

1 Like

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

Synchronous code is executed in sequence, where each function block is dependent on the previous block finishing before it can be executed. Asynchronous code doesn’t need to wait as the functions are set aside and executed at a later stage so the main program can keep running, meaning a webpage or app will remain responsive and prevent the end user having to waste time waiting on each piece of code to complete.

2. What is callback hell?

It’s a conventional name given to poor coding practice. A callback is a function that’s passed to another function as an argument to be executed later, and when this repeatedly happens and say the second function then gets passed to a third function, and so on, callback hell can develop. This can make the code that much harder to read and decipher what its actual purpose is.

3. Which technique can help us solve callback hell?

To try and not use nested functions where possible but instead give each a meaningful name and declare them at the top level, making it easier to modularize the overall code. Adding comments where appropriate will also make the program easier to read. Other techniques are async await syntax, where we actually declare an async function in JavaScript and it knows to expect the possibility of the await keyword being used to invoke asynchronous code. This is used in conjunction with Promises, which is yet another technique used to solve callback hell, where Promise objects represent the eventual completion (or failure) of an asynchronous operation and its resulting value.

1 Like