Bird
0
0

What will happen if you try to share a large JavaScript object directly between worker threads using worker.postMessage() without transferring ownership?

medium📝 component behavior Q5 of 15
Node.js - Worker Threads
What will happen if you try to share a large JavaScript object directly between worker threads using worker.postMessage() without transferring ownership?
AThe object is shared by reference with no cloning
BThe object is cloned and sent, causing performance overhead
CAn error is thrown because objects cannot be sent
DThe object is automatically converted to a string
Step-by-Step Solution
Solution:
  1. Step 1: Understand worker.postMessage behavior

    By default, objects sent via postMessage are cloned, not shared by reference.
  2. Step 2: Consider performance impact

    Cloning large objects causes overhead, which can slow down communication.
  3. Final Answer:

    The object is cloned and sent, causing performance overhead -> Option B
  4. Quick Check:

    postMessage clones objects unless transferred [OK]
Quick Trick: postMessage clones objects unless transferred [OK]
Common Mistakes:
  • Assuming objects are shared by reference
  • Expecting errors when sending objects
  • Thinking objects convert to strings automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes