O'Reilly logo

JavaScript Absolute Beginner’s Guide by Kirupa Chinnathambi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required