Quiz

  1. I'm still a little confused about the execution time for ajax and normal functions that uses a return value. For example, would console.log(ex1.get('harry')); takes longer to execute compared to ex1.get('harry', console.log);? Since the order of execution remains unchanged, I feel like they should take the same amount of time.

    It's not the time, it's the waiting. In both cases, ex1.get('harry') happens first, but then it either:

    • Returns a value to the caller, who has been waiting, or
    • Invokes a callback.

    When we are dealing with network delays, we don't want the JavaScript running in our browser to sit and wait, because then it can't do anything else.

    Instead, when the data comes back, JS will invoke a callback function.

    So nothing sits around waiting, keeping other things from running.

  2. There is nothing more I would like to talk about. / Everything is clear

    Amazing! Ajax can be complicated and confusing, so I'm glad you're off to a good start.