heavy-computation.js
✓ Published0🌍 Public
Aalessioalex
Last edited Nov 22, 2014
Created on Nov 22, 2014
This example demonstrates the blocking behavior of a single-threaded JavaScript event loop. A heavy computation—summing all even numbers up to 199,999,999—runs synchronously inside `displaySum`, which prevents a concurrent `setInterval` callback from logging "I'm alive!!" every 200 milliseconds. The code measures the sum’s duration with `console.time` and `console.timeEnd`, showing that the interval remains silent until the loop finishes. It highlights the challenge of keeping a UI or process responsive during CPU-intensive tasks, a limitation relevant to both browsers and Node.js.
AI-generated description