6. Timers
In This Chapter
• Learn how to delay when your code runs
• Figure out several ways to run your code repeatedly without blocking your entire app
By default, your code runs synchronously. That is a fancy of way of saying that when a statement needs to execute, it executes immediately. There are no ifs, ands, or buts about it. The concept of delaying execution or deferring work to later isn’t a part of JavaScript’s default behavior. That doesn’t mean the ability to delay work to a later time doesn’t exist! If you swerve just slightly off the main road, there are three functions that allow you to mostly do just that (and more). Those functions are setTimeout
, setInterval
, and requestAnimationFrame
.
In this chapter, we look at what each ...
Get JavaScript Absolute Beginner’s Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.