Sequential, synchronous, asynch.


I need to know whether javascript execution is sequential or not.

The things is that i have a progress bar in my js but it simply executes fast and gets hidden since my successive js is hiding it. How can i block the execution for this sake?
Is a callback ensuring this blocking?
Also a simple explanation with sync and async would also be nice.

LVL 12
Who is Participating?
David S.Connect With a Mentor Commented:
Callbacks are not sequential -- they'll be called whenever the thing (e.g. UI event or AJAX request) they are waiting on finishes or happens. There wouldn't be much point to callbacks if they were blocking. Callbacks do not wait for the parent function to execute.
David S.Connect With a Mentor Commented:
Most JavaScript execution is sequential, however, setTimeout(), setInterval(), and AJAX (except for the rarely used synchronous AJAX requests) cause code to be executed out of sequence.

Since most browsers use a single thread for UI and JavaScript, blocking is a very bad idea because the browser will become unresponsive, which other than completely crashing a browser is about the worst thing your script can do.

Callbacks don't block. They simply cause a function to be executed after a set time or after a certain event takes place, e.g. a response is received for an AJAX request or the user clicks on something.

I recommend you ask  a new question about how to restructure your code to work as intended.
jazzIIIloveAuthor Commented:
Are callbacks sequential? and blocking? (do they wait for their parent function to execute?)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.