Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Asynchronous Programming with JavaScript!
You have completed Asynchronous Programming with JavaScript!
Preview
This video shows you examples of synchronous and asynchronous JavaScript in the browser.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
First, I'll show you an example of the
blocking behavior of synchronous code in
0:00
the browser.
0:00
I have this function named wait,
consisting of
0:01
a while loop that runs continuously for
8,000 milliseconds or 8 seconds.
0:03
Below the function, there's an
EventListener that calls the wait function
0:08
when the red button up here
on the page is clicked.
0:11
Notice how in the body of the wait
function, the start variable and
0:14
while loop are between a console.log
statement that logs the message, starting,
0:18
and one that logs the message, finished.
0:23
Over in the browser,
0:25
let's have a look at what happens when I
click the button to call the function.
0:26
In the console,
we immediately see the message, starting,
0:29
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up