The web worker is used effectively in multi core processors.
Types of web workers
- Dedicated workers
- Shared workers
Dedicated workers are accessible by the scripts from where they are loaded.
Shared workers are accessible by multiple scripts.
var num = prompt(“Enter a number”);
num = parseInt(num);
alert(“Enter a Number”);
else if (num == 0)
alert(“The number is zero”);
else if (num%2)
alert(“The number is odd”);
alert(“The number is even”);
The main program which calls postMessage() function
<title>web worker example<title>
<p>The number is even or odd <output id=”result”></output></p>
var worker = new worker(“evenorodd.js”);
worker.onmessage = function (event)
document.getElementById(“result”).textcontent = event.data;