Skip to main content

What does zone.js do when the application starts?

In Angular, zone.js is a library that tracks asynchronous operations in the application and helps Angular automatically run change detection after they complete.

Key points

  1. Intercepting asynchronous events
  • zone.js "wraps" timers (setTimeout, setInterval), promises, HTTP requests, and DOM events.
  • When such operations complete, Angular knows it needs to update the interface.
  1. Automatically running change detection
  • After every asynchronous event, Angular automatically checks the components and updates the DOM.
  • This frees the developer from having to call detectChanges() manually.
  1. When the application starts
  • zone.js is picked up in main.ts through the import 'zone.js' import.
  • All the application's asynchronous tasks fall inside the "zone," and Angular tracks their completion.

In other words, zone.js provides automatic change detection after asynchronous operations, which lets the interface always stay up to date without manual intervention.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.