I'm just beginning to learn about asynchronous JavaScript so I'm not sure if this is a silly question, but I could not find an answer to it directly.
In the examples of asynchronous JS I've seen the asynchronous logic is always called after the synchronus logic, that is to say last. Something like:
function1() {}
asynchronousFunction(){}
function2(){}
Isn't this the equivalent of:
function1(){}
function2(){}
function3(){} //asynchronous function
Isn't an asynchronous call the same as a function call at the top of the stack of the main thread, since the asynchronous call is seems to always be made after anything that is synchronous ?
Thanks for any help on this !
Asynchronous functions in JS are used to do something that requires time, e.g. downloading some data, or calculating something. Of corse you can do it synchronously but your view will freeze, and no one want that.
It is not true that async functions run after all sync. (It starts like normal synch function but end when 'task' is done.
More: Link
You should also read more about AJAX.