Asynchronous Programming - Reading Assignment

What is the difference between synchronous and asynchronous functions?
-synchronous function needs full attention. Like JavaScript can not do multiple functions at the same time because it single-threading environment.
-asynchronous functions can be put on the side to be executed for a specific time or event.
What is callback hell?
-When complex operations produces several levels and sub-levels.
Which technique can help us solve callback hell?
-In jQuery we can us promises: it enables us to chain call backs and deal with errors.
-In Node.js we can extend the running time example with document.ready

  1. Synchronous has to be finished and then JS will start executing other code, and Asynchronous you can call a function and sort of wait until it will meet the conditions needed.
    2.Callback hell - is the situation you want to avoid. It makes the code harder to maintain and debug.
  2. Technique called promises can help solve it.
  1. In a Synchronous function each task has to finished before starting the next one(First preparing the bed, than go to sleep). In a asynchronous function, you can start with one task and while waiting for the reply, you can work on another task( Putting a pizza in the oven, than watching a game, while waiting the pizza to get ready).

  2. A callback hell is a complex operation produces several levels and sub-levels of reply.

  3. Which technique can help us solve callback hell?

  • In jQuery we can use the built-in promise library.
  • In Node.js we can change the asynchronous function and let it run in a synchronous style (wait).

I had a same problem. I just turned off Brave shields and then it loaded

  1. Synchronous functions lock up the program and will wait until they get the desired answer, while asynchronous function will be able to do other things while still waiting for the information it needed earlier.
  2. A function that calls back a function which calls an another function and so on is what we call a callback hell.
  3. We can use promises which actually comes with JQuery.

What is the difference between synchronous and asynchronous functions?

Synchronous execute until they complete without allowing other code to run.

Asynchronous functions allow other code to run once started, and resume later as defined by the function

What is callback hell?

A term used to refer to growing complexity of code as functions are layered to produce multiple outputs

Which technique can help us solve callback hell?

“jQuery ships with a simple built-in promise library that enables us to chain callbacks and deal with errors.”

  1. In synchronous programming, each step is performed one after the previous one is finished executing. In asynchronous, step 2 will be performed even if step 1 isn’t finished.
  2. The cause of callback hell is when people try to write JavaScript in a way where execution happens visually from top to bottom.
  3. Solve callback hell:
    A. Don’t nest functions. Give them names and place them at the top level of your program
    B. Use function hoisting to your advantage to move functions ‘below the fold’
    C. Handle every single error in every one of your callbacks. Use a linter like standard to help you with this.
    D. Create reusable functions and place them in a module to reduce the cognitive load required to understand your code. Splitting your code into small pieces like this also helps you handle errors, write tests, forces you to create a stable and documented public API for your code, and helps with refactoring.
  1. What is the difference between synchronous and asynchronous functions?
    When you call a synchronous function your program will wait for a response before it can continue executing. However, an asynchronous function does not provide an immediate response and will therefore allow the calling code to continue executing whilst the function executes in a different thread.

  2. What is callback hell?
    There may be complex systems where multiple asynchronous functions are nested, producing multiple callback levels or, where many asynchronous functions are fired simultaneously. It can be difficult to coordinate correct control flow in such an environment, which leads to a situation known as Callback Hell.

  3. Which technique can help us solve callback hell?
    Whilst jQuery ships with Promises that help chain callbacks for better error handling, using Meteor can extend the Node.js runtime by abstracting the synchronicity aspect of nested functions so as to present them in a synchronous manner.

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

Synchronous = have to focus on one task until it’s completed
Asynchronous = can start a task and then set it aside to do other things while completing the task in the background

  1. What is callback hell?

When you have many different layers of code running at the same time. Your code can start to look like a pyramid because of all of the layers, indentations, and closing brackets. It can be very difficult to read.

  1. Which technique can help us solve callback hell?

Promises. They enable us to chain callbacks and deal with errors. The code is much easier to read and looks much more consolidated.

  1. What is the difference between synchronous and asynchronous functions?
    A synchronous function occupies Javascript entirely because only one section of the code can run at a time. On the other hand, an asynchronous function can have tasks initiated and then put aside until a later time so more than one section of the code in the function can run at the same time.

  2. What is callback hell?
    Callback hell happens when there are too many nested callbacks in functions making it hard to read and maintain (like hell).

  3. Which technique can help us solve callback hell?
    We can help solve a callback hell by implementing promises. Promises help us naturally handle errors, and write cleaner code by not having callback parameters, and without modifying the underlying architecture. It represents the result of an asynchronous operation.

image

  1. What is the difference between synchronous and asynchronous functions? Synchronous functions take up the browser’s full attention until completion and can only be completed one at a time. Asynchronous functions can be initiated and put aside for completion at a later time allowing the browser to complete other tasks in the meantime.
  2. What is callback hell? Callback hell occurs when levels of nested functions used for complex operations produce excessive callbacks and/or callback errors.
  3. Which technique can help us solve callback hell? We can use Promises to chain callbacks and deal with errors or extend the runtime and abstract away the asynchronicity so the code appears synchronous.

1.What is the difference between synchronous and asynchronous functions?
Synchronous function are blocking the code till their execution, while asynchronous functions can be put aside and execute later.

2.What is callback Hell?
Many callbacks nested in the function , which make the function complex.

3.Which technique can help us solve callback hell?
Promises.

  1. Synchronous functions need to be handled one at a time, and cannot move on to the next one until it is finished while asynchronous can be operating in the background while a synchronous function is being carried out.
  2. Callback hell is a nesting doll of functions and the outer functions cannot perform until the one inside it is complete.
  3. You can solve it with a “promise”
  1. synchronous function blocks the js thread until the execution is finisched, asynchronous do not
  2. for simple tasks many nested functions where needed
  3. Promises can solve the callback hell
  1. What is the difference between synchronous and asynchronous functions?
    Synchronous functions block the code until they are finished being executed, asynchronous functions can allow for more time for the browser to complete other tasks before being executed.
  2. What is callback hell?
    Excessive use of callbacks which produce more levels and sublevels than are necessary which will make it harder to maintain.
  3. Which technique can help us solve callback hell?
    Promises
  1. What is the difference between synchronous and asynchronous functions?

While a synchronous task will occupy our program continuously until its completion, an asynchronous one will delay its completion until a certain answer arrives, so that the program can still running, doing other tasks. Therefore, the asynchronous task will not lock the browser up.

  1. What is callback hell?

When you have complex operations that requires several levels with sub-levels, all of them with nested functions in it.

  1. Which technique can help us solve callback hell?

For the browser, we could use promises from jQuery. For Node.js, we can extend the runtime.

  1. Once invoked, synchronous functions (also called blocking functions) have to run their code from start to finish, and complete their task, before the browser can move on to perform other operations. This isn’t an issue with operations that can be performed instantaneously, as the browser can move on from them immediately, and so doesn’t get blocked.
    However, operations such as network requests for data from other servers (Ajax requests) take longer to complete and would block the browser if performed using synchronous functions. Instead, asynchronous functions enable the browser to initiate these kinds of operations, and then to continue executing other code while waiting for the asynchronous operation to complete, or for an error message to be thrown if it fails. The asynchronous function achieves this by including a callback function as one of its parameters.

  2. The term callback hell descibes code that uses multiple levels of nested callback functions (often referred to as the pyramid of doom) to perform a complex set of asynchronous operations with interdependent inputs and outputs. This approach often results in dense and convoluted code with a confusing control flow, which is therefore difficult to read, debug and develop further.

  3. Converting asynchronous functions into JavaScript promises can help us solve callback hell. Promises are objects that have one of three states. Before its asynchronous operation completes, a promise is pending. On completion, and depending on whether the operation has been successful or not, the promise’s state will change to either fulfilled or rejected, and it will also be assigned the value generated by whichever of these two alternatives is the outcome e.g. the requested data, or an error message.
    Using promises results in code which is easier to read, debug and develop further, for the following reasons:
    (i)  Promises adopt a modular approach to complex sets of asynchronous operations;
    (ii) Unlike standard asynchronous functions, promises don’t need to use callback parameters
       for success and error handling;
    (iii) Instead, promises enable success and error handling to be managed and performed using
       chained  .then()  and  .catch()  methods. This chaining of operations results in code
       with a synchronous style of control flow.
    Apart from promises, other solutions to callback hell include using a package such as
    node-fibers , or the ES8  async...await  syntax, both of which can be used to write what is essentially asynchronous code, but in a clearer style, and with a control flow that makes it appear synchronous.

1.Synchronous functions are when two or more things happen at the same time, a direct interaction, asynchronous is the opposite, things are processed indirectly

2.Callback hell is a way to freeze a computation and have it execute later (asynchronous) to put at rest inside a callback

3.Callback hell can be solved by using promises, ie the next part of the code is executed, but will return to check

I am unable to access the blog post of the assignment.
I get this Message:
"
This site can’t provide a secure connection
www.discovermeteor.com sent an invalid response.
ERR_SSL_PROTOCOL_ERROR
"