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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David S.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?)

David S.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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.