Workers themselves have access to the self object, to which you can attach similar event listeners, as previously discussed. Let us see how that goes:
// myworker.jsself.addEventListener('message', e => { console.log(e.data); // data sent by main script});
Here, the message event listener is fired whenever the main script sends a message to this particular web worker. We simply console-log what the main script sent with console.log(e.data).