Web Workers in JavaScripts.

How can we achieve concurrency in Javascript?

let worker = new Worker('web-worker.js');
// main.js
let worker = new Worker('web-worker.js');
worker.addListener('message',(e) => {
console.log('Hey! Workers Said : ', e.data);
},false);
worker.postMessage('This message is from Parent to Web Worker');
// web-worker.js
self.addEventListener('message', function(e) {
self.postMessage(e.data);
}, false);

Explanation

--

--

Hey 👋, I am Adarsh, a Web Developer from 🇮🇳

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store