7

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, our 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. We kind of saw this when looking at loops earlier. The loop runs at lightning speed with no delay between each iteration. That is great for making quick calculations, but that isn’t great if we want to make an update at a more measured (that is, slower) pace.

All of this doesn’t mean the ability to stop work ...

Get Javascript Absolute Beginner's Guide, 3rd Edition 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.