0

Like in the standard juery / javascript animation effects. How does javascript know that it doesn't have to wait for a animation to finish before executing the code in the lines beneathe it, because the code gets executed line by line, but how does it know that it doesn't have to properly wait for a function to get a response or it to finish? is this written somewhere in the source code of the those javascript functions or where is this functionality programmed? Same thing goes for the ajax call, how does javascript know that it can do other stuff while it is waiting for a respone?....I really want to understand this in depth...

I've read a lot of articles about asynchronous behaviour / callbacks. I get those points, but I've still not found anywhere on the web, that explains how it is implemented.

GSingh
  • 1
  • 1
  • 1
    It's async. Asynchronous functions return immediately and run in the background. If you want to execute some code when it finishes, you'll need to implement a callback mechanism. – Carcigenicate Jul 23 '17 at 17:50
  • Note the duplicate references AJAX, but the pattern is the same for any async operation – Rory McCrossan Jul 23 '17 at 17:53
  • Where is the code that you are inquiring about? – guest271314 Jul 23 '17 at 17:53
  • This is what I found on stackoverflow reading older topics. Someone had this question, that the fadeIn happenes before the fadeOut animation is finsihed. "$('.sidebarform').fadeOut('slow'); $('.sidebarsuccess').fadeIn('slow');" A person told him to use fadeIn as a callback "The fadeOut function has a callback that it executes when the animation is done: $('.sidebarform').fadeOut('slow', function() { $('.sidebarsuccess').fadeIn('slow'); });" – GSingh Jul 23 '17 at 18:17
  • --------------------------------------- What I still don't understand is javascript's behavior why is it not waiting for fadeOut to finish before executing fadeIn, I get the deal to prevent this callbacks are needed, BUT WHY DOES JAVASCRIPT do this. – GSingh Jul 23 '17 at 18:21
  • @GSingh _"What I still don't understand is javascript's behavior why is it not waiting for fadeOut to finish before executing fadeIn"_ Can you reproduce the issue at stacksnippets, jsfiddle http://jsfiddle.net or plnkr https://plnkr.co? – guest271314 Jul 23 '17 at 18:44

0 Answers0