{"id":41821,"date":"2017-11-23T21:01:42","date_gmt":"2017-11-23T13:01:42","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=41821"},"modified":"2025-04-04T02:50:53","modified_gmt":"2025-04-03T18:50:53","slug":"shared-memory-in-javascript","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/shared-memory-in-javascript\/","title":{"rendered":"Introduction to Shared Memory in JavaScript"},"content":{"rendered":"<p><strong>Shared memory<\/strong> is an advanced feature of JavaScript, that threads (concurrently executed parts of a process) can leverage. Sharing the memory means <strong>not having the trouble of passing updated data between threads<\/strong> and all threads can access and update the same data in the shared memory.<\/p>\n<p>Doesn\u2019t that sound lovely? Well, almost. In this post, we\u2019ll see <strong>how to use shared memory in JavaScript<\/strong> and how to decide if this is what you really want to do.<\/p>\n<p class=\"note\"><strong>Read Also:<\/strong> <a target=\"_blank\" href=\"https:\/\/www.hongkiat.com\/blog\/object-oriented-javascript\/\" rel=\"noopener\">Object-Oriented JavaScript (OOJS): 3 Ways to Create Object Instances<\/a><\/p>\n<h2>Advantages & disadvantages of shared memory<\/h2>\n<p>We use <strong><a href=\"https:\/\/www.hongkiat.com\/blog\/web-workers-javascript-api\/\">web workers<\/a><\/strong> to <strong>create threads in JavaScript<\/strong>. The Web Workers API allows us to create worker threads that can be used to <strong>execute code in the background<\/strong> so that the main thread is free to continue its execution, possibly processing UI events, ensuring no UI freeze.<\/p>\n<p>Worker threads <strong>run concurrently with the main thread and each other<\/strong>. Such simultaneous execution of different parts of a task is time-saving. You finish quicker, but it also has its own set of problems.<\/p>\n<p>Making sure that each thread <strong>gets the necessary resources and communicates with each other in a timely manner<\/strong> is a task in itself, where a mishap can result in a surprising outcome. Or, if <strong>one thread is changing data and another one is reading it <em>at the same time<\/em><\/strong>, what do you think the other thread will see? The updated or the old data?<\/p>\n<p>However, web workers are not so easy to screw up. During their communication via using messages, the data they send each other is <strong>not original but a copy<\/strong>, meaning they don\u2019t <em>share<\/em> the same data. They <strong>pass copies of data to each other<\/strong> when needed.<\/p>\n<p>But sharing is caring, and multiple threads might also need to look at the same data at the same time and change them.  So, <strong>banning sharing is a big no-no<\/strong>. This is where the <a target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/SharedArrayBuffer\" rel=\"noopener\"><code>SharedArrayBuffer<\/code><\/a> object comes into the picture. It will let us <strong>share binary data between multiple threads<\/strong>.<\/p>\n<h2>The <code>SharedArrayBuffer<\/code> object<\/h2>\n<p>Instead of passing the data copies between threads, we <strong>pass copies of the <code>SharedArrayBuffer<\/code> object<\/strong>. A <code>SharedArrayBuffer<\/code> object <strong>points to the memory where the data is saved<\/strong>.<\/p>\n<p>So, even when the copies of <code>SharedArrayBuffer<\/code> are passed between threads, they <strong>all will still point to the same memory<\/strong> where the original data is saved. The threads, thus, can <strong>view and update the data in that same memory<\/strong>.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/shared-memory-in-javascript\/shared-memory.jpg\" alt=\"Shared Memory and Web Workers Diagram\" width=\"900\" height=\"426\"><\/figure>\n<h2>Web workers <em>without<\/em> shared memory<\/h2>\n<p>To see how a web worker works without using shared memory, we <strong>create a worker thread<\/strong> and <strong>pass some data to it<\/strong>.<\/p>\n<p>The <code>index.html<\/code> file holds the <strong>main script<\/strong> inside a <code>&lt;script&gt;&lt;\/script&gt;<\/code> tag, as you can see it below:<\/p>\n<pre>\r\nconst w = new Worker('worker.js');\r\nvar \tn = 9;\r\nw.postMessage(n);\r\n<\/pre>\n<p>The <code>worker.js<\/code> file carries the <strong>worker script<\/strong>:<\/p>\n<pre>\r\nonmessage = (e)=&gt;{\r\n  console.group('[worker]');\r\n  console.log('Data received from main thread: %i', e.data);\r\n  console.groupEnd();\r\n}\r\n<\/pre>\n<p>Using the code above, we get the following <strong>output in the console<\/strong>:<\/p>\n<pre>\r\n[worker]\r\nData received from main thread: 9\r\n<\/pre>\n<p>You can read <a href=\"https:\/\/www.hongkiat.com\/blog\/web-workers-javascript-api\/\">my aforementioned post on web workers<\/a> for the full code explanation of the above snippets.<\/p>\n<p>For now, keep in mind that data is <strong>sent back and forth between threads<\/strong> using the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Worker\/postMessage\" target=\"_blank\" rel=\"noopener\"><code>postMessage()<\/code><\/a> method. The data is <strong>received on the other side by the <code>message<\/code> event handler<\/strong>, as the value of the event\u2019s <code>data<\/code> property.<\/p>\n<p>Now, if we <strong>change the data<\/strong> will it appear updated at the receiving end? Let\u2019s see:<\/p>\n<pre>\r\nconst w = new Worker('worker.js');\r\nvar \tn = 9;\r\nw.postMessage(n);\r\nn = 1;\r\n<\/pre>\n<p>As expected, the<strong> data has <em>not<\/em> been updated<\/strong>:<\/p>\n<pre>\r\n[worker]\r\nData received from main thread: 9\r\n<\/pre>\n<p>Why would it be, anyway? It\u2019s <strong>just a clone sent to the worker from the main script<\/strong>.<\/p>\n<h2>Web workers <em>with<\/em> shared memory<\/h2>\n<p>Now, we will <strong>use the <code>SharedArrayBuffer<\/code> object<\/strong> in the same example. We can create a new <code>SharedArrayBuffer<\/code> instance by <strong>using the <code>new<\/code> keyword<\/strong>. The constructor takes one parameter; a <strong>length value in bytes<\/strong>, specifying the size of the buffer.<\/p>\n<pre>\r\nconst w = new Worker('worker.js');\r\nbuff = new SharedArrayBuffer(1);\r\nvar \tarr = new Int8Array(buff);\r\n\/* setting data *\/\r\narr[0] = 9;\r\n\/* sending the buffer (copy) to worker *\/\r\nw.postMessage(buff);\r\n<\/pre>\n<p>Note that a <code>SharedArrayBuffer<\/code> object <strong>represents only a shared memory area<\/strong>. To <strong>see and change the binary data<\/strong>, we need to use an appropriate data structure  (a <a target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/TypedArray\" rel=\"noopener\"><code>TypedArray<\/code><\/a> or a <a target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/DataView\" rel=\"noopener\"><code>DataView<\/code><\/a> object).<\/p>\n<p>In the <code>index.html<\/code> file above, a new <code>SharedArrayBuffer<\/code> is created, with only one-byte length. Then, a new <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Int8Array\" target=\"_blank\" rel=\"noopener\"><code>Int8Array<\/code><\/a>, which is one type of <code>TypedArray<\/code> objects, is used to <strong>set the data to \u201c9\u201d in the provided byte space<\/strong>.<\/p>\n<pre>\r\nonmessage = (e)=&gt;{\r\n  var arr = new Int8Array(e.data);\r\n  console.group('[worker]');\r\n  console.log('Data received from main thread: %i', arr[0]);\r\n  console.groupEnd();\r\n}\r\n<\/pre>\n<p><code>Int8Array<\/code> is also used in the worker, to <strong>view the data in the buffer<\/strong>.<\/p>\n<p>The <strong>expected value appears in the console<\/strong> from the worker thread, which is exactly what we wanted:<\/p>\n<pre>\r\n[worker]\r\nData received from main thread: 9\r\n<\/pre>\n<p>Now, let\u2019s <strong>update the data in the main thread<\/strong> to see if the change is reflected in the worker.<\/p>\n<pre>\r\nconst w = new Worker('worker.js'),\r\nbuff = new SharedArrayBuffer(1);\r\nvar \tarr = new Int8Array(buff);\r\n\/* setting data *\/\r\narr[0] = 9;\r\n\/* sending the buffer (copy) to worker *\/\r\nw.postMessage(buff);\r\n\/* changing the data *\/\r\narr[0] = 1;<\/pre>\n<p>And, as you can see below, the update <strong>does reflect inside the worker<\/strong>!<\/p>\n<pre>\r\n[worker]\r\nData received from main thread: 1\r\n<\/pre>\n<p>But, the code also<strong> needs to work the other way around<\/strong>: when the value in the worker changes at first, it <strong>also needs to be updated<\/strong> when it\u2019s printed from the main thread.<\/p>\n<p>In this case, our code looks like this:<\/p>\n<pre>\r\nonmessage = (e)=&gt;{\r\n  var arr = new Int8Array(e.data);\r\n  console.group('[worker]');\r\n  console.log('Data received from main thread: %i', arr[0]);\r\n  console.groupEnd();\r\n  \/* changing the data *\/\r\n  arr[0] = 7;\r\n  \/* posting to the main thread *\/\r\n  postMessage('');\r\n}\r\n<\/pre>\n<p>The <strong>data is changed in the worker<\/strong> and an <strong>empty message is posted to the main thread<\/strong> signalling that the data in the buffer has been changed and is ready for the main thread to be outputted.<\/p>\n<pre>\r\nconst w = new Worker('worker.js'),\r\nbuff = new SharedArrayBuffer(1);\r\nvar \tarr = new Int8Array(buff);\r\n\/* setting data *\/\r\narr[0] = 9;\r\n\/* sending the buffer (copy) to worker *\/\r\nw.postMessage(buff);\r\n\/* changing the data *\/\r\narr[0] = 1;\r\n\/* printing the data after the worker has changed it *\/\r\nw.onmessage = (e)=&gt;{\r\n  console.group('[main]');\r\n  console.log('Updated data received from worker thread: %i', arr[0]);\r\n  console.groupEnd();\r\n}\r\n<\/pre>\n<p>And, this works, too! <strong>The data in the buffer is same as the data inside the worker.<\/strong><\/p>\n<pre>\r\n[worker]\r\nData received from main thread: 1\r\n[main]\r\nUpdated data received from worker thread: 7\r\n<\/pre>\n<p>The value <strong>appears updated in both the cases<\/strong>; both the main and worker threads are viewing and changing the same data.<\/p>\n<h2>Final words<\/h2>\n<p>As I\u2019ve mentioned earlier, using shared memory in JavaScript <strong>is not without downsides<\/strong>. It\u2019s up to developers to ensure that the <strong>sequence of execution happens as predicted<\/strong> and no two threads are racing to get the same data because no one knows who will take the trophy.<\/p>\n<p>If you are interested in shared memory more, have a look at the documentation of the <a target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Atomics\" rel=\"noopener\"><code>Atomics<\/code><\/a> object. The <strong>Atomics object can help you with some of the hardships<\/strong>, by reducing the unpredictable nature of reading\/writing from the shared memory.<\/p>\n<p class=\"note\"><strong>Read Also:<\/strong> <a target=\"_blank\" href=\"https:\/\/www.hongkiat.com\/blog\/javascript-promise-object\/\" rel=\"noopener\">Getting Started with JavaScript Promises<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>Shared memory is an advanced feature of JavaScript, that threads (concurrently executed parts of a process) can leverage. Sharing the memory means not having the trouble of passing updated data between threads and all threads can access and update the same data in the shared memory. Doesn\u2019t that sound lovely? Well, almost. In this post,&hellip;<\/p>\n","protected":false},"author":145,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3392],"tags":[4117,511],"topic":[4520],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.6) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Introduction to Shared Memory in JavaScript - Hongkiat<\/title>\n<meta name=\"description\" content=\"Shared memory is an advanced feature of JavaScript, that threads (concurrently executed parts of a process) can leverage. Sharing the memory means not\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hongkiat.com\/blog\/shared-memory-in-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Introduction to Shared Memory in JavaScript\" \/>\n<meta property=\"og:description\" content=\"Shared memory is an advanced feature of JavaScript, that threads (concurrently executed parts of a process) can leverage. Sharing the memory means not\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/shared-memory-in-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2017-11-23T13:01:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-03T18:50:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/assets.hongkiat.com\/uploads\/shared-memory-in-javascript\/shared-memory.jpg\" \/>\n<meta name=\"author\" content=\"Preethi Ranjit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Preethi Ranjit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/shared-memory-in-javascript\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/shared-memory-in-javascript\\\/\"},\"author\":{\"name\":\"Preethi Ranjit\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e981676afae36d1ff5feb75094950ab3\"},\"headline\":\"Introduction to Shared Memory in JavaScript\",\"datePublished\":\"2017-11-23T13:01:42+00:00\",\"dateModified\":\"2025-04-03T18:50:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/shared-memory-in-javascript\\\/\"},\"wordCount\":946,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/shared-memory-in-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/shared-memory-in-javascript\\\/shared-memory.jpg\",\"keywords\":[\"Javascripts\",\"Web Developers\"],\"articleSection\":[\"Coding\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/shared-memory-in-javascript\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/shared-memory-in-javascript\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/shared-memory-in-javascript\\\/\",\"name\":\"Introduction to Shared Memory in JavaScript - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/shared-memory-in-javascript\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/shared-memory-in-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/shared-memory-in-javascript\\\/shared-memory.jpg\",\"datePublished\":\"2017-11-23T13:01:42+00:00\",\"dateModified\":\"2025-04-03T18:50:53+00:00\",\"description\":\"Shared memory is an advanced feature of JavaScript, that threads (concurrently executed parts of a process) can leverage. Sharing the memory means not\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/shared-memory-in-javascript\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/shared-memory-in-javascript\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/shared-memory-in-javascript\\\/#primaryimage\",\"url\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/shared-memory-in-javascript\\\/shared-memory.jpg\",\"contentUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/shared-memory-in-javascript\\\/shared-memory.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/shared-memory-in-javascript\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Introduction to Shared Memory in JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e981676afae36d1ff5feb75094950ab3\",\"name\":\"Preethi Ranjit\",\"description\":\"A .NET developer with a JavaScript background, Preethi is expert in front-end coding, JavaScript, HTML, and CSS.\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/preethi\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Introduction to Shared Memory in JavaScript - Hongkiat","description":"Shared memory is an advanced feature of JavaScript, that threads (concurrently executed parts of a process) can leverage. Sharing the memory means not","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.hongkiat.com\/blog\/shared-memory-in-javascript\/","og_locale":"en_US","og_type":"article","og_title":"Introduction to Shared Memory in JavaScript","og_description":"Shared memory is an advanced feature of JavaScript, that threads (concurrently executed parts of a process) can leverage. Sharing the memory means not","og_url":"https:\/\/www.hongkiat.com\/blog\/shared-memory-in-javascript\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2017-11-23T13:01:42+00:00","article_modified_time":"2025-04-03T18:50:53+00:00","og_image":[{"url":"https:\/\/assets.hongkiat.com\/uploads\/shared-memory-in-javascript\/shared-memory.jpg","type":"","width":"","height":""}],"author":"Preethi Ranjit","twitter_card":"summary_large_image","twitter_creator":"@hongkiat","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Preethi Ranjit","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/shared-memory-in-javascript\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/shared-memory-in-javascript\/"},"author":{"name":"Preethi Ranjit","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e981676afae36d1ff5feb75094950ab3"},"headline":"Introduction to Shared Memory in JavaScript","datePublished":"2017-11-23T13:01:42+00:00","dateModified":"2025-04-03T18:50:53+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/shared-memory-in-javascript\/"},"wordCount":946,"commentCount":0,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/shared-memory-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/shared-memory-in-javascript\/shared-memory.jpg","keywords":["Javascripts","Web Developers"],"articleSection":["Coding"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.hongkiat.com\/blog\/shared-memory-in-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/shared-memory-in-javascript\/","url":"https:\/\/www.hongkiat.com\/blog\/shared-memory-in-javascript\/","name":"Introduction to Shared Memory in JavaScript - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/shared-memory-in-javascript\/#primaryimage"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/shared-memory-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/shared-memory-in-javascript\/shared-memory.jpg","datePublished":"2017-11-23T13:01:42+00:00","dateModified":"2025-04-03T18:50:53+00:00","description":"Shared memory is an advanced feature of JavaScript, that threads (concurrently executed parts of a process) can leverage. Sharing the memory means not","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/shared-memory-in-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/shared-memory-in-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/shared-memory-in-javascript\/#primaryimage","url":"https:\/\/assets.hongkiat.com\/uploads\/shared-memory-in-javascript\/shared-memory.jpg","contentUrl":"https:\/\/assets.hongkiat.com\/uploads\/shared-memory-in-javascript\/shared-memory.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/shared-memory-in-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Introduction to Shared Memory in JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e981676afae36d1ff5feb75094950ab3","name":"Preethi Ranjit","description":"A .NET developer with a JavaScript background, Preethi is expert in front-end coding, JavaScript, HTML, and CSS.","url":"https:\/\/www.hongkiat.com\/blog\/author\/preethi\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-aSx","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/41821","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/145"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=41821"}],"version-history":[{"count":2,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/41821\/revisions"}],"predecessor-version":[{"id":73741,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/41821\/revisions\/73741"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=41821"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=41821"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=41821"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=41821"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}