Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumNodeJSWorker threads basicsSingle-choice MCQ

A worker is created with `new Worker(__filename)`. When you pass a `Buffer` via `worker.postMessage(buf)` and then read `buf.length` on the main thread afterward, the buffer is still fully intact. But when you pass an `ArrayBuffer` in the transfer list, reading it afterward shows length 0. Why?

const { Worker, isMainThread, parentPort } = require('node:worker_threads'); if (isMainThread) { const w = new Worker(__filename); const ab = new ArrayBuffer(8); w.postMessage(ab, [ab]); console.log(ab.byteLength); // ? }