JavaScript · Senior · Question 27 of 75

How do you avoid blocking the UI when processing 100,000 items on the main thread?

Explanation

Tasks longer than 50 ms hurt responsiveness (INP). async doesn't create a new thread: a synchronous loop inside still blocks. Cut the work into pieces and yield via setTimeout, scheduler.yield() (where supported) or requestIdleCallback; move heavy computation to a Web Worker.

Further reading

Problem with a question

JavaScript · Senior · question 27

Test yourself

Take the JavaScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz