Async Web Workers
Workers run code outside the page main thread and communicate through messages. A small message handler can be tested without creating another worker.
Where to run this
This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.
A practical example
function handleMessage(data) {
return {total: data.count * data.price};
}
console.log(handleMessage({count: 3, price: 6}));
What happens
The pure worker calculation returns a total of 18.