Bird
0
0

Which of the following is the correct syntax to listen for messages from a worker in Node.js?

easy📝 Syntax Q12 of 15
Node.js - Worker Threads
Which of the following is the correct syntax to listen for messages from a worker in Node.js?
Aworker.on('message', (result) => { console.log(result); });
Bworker.listen('message', (result) => { console.log(result); });
Cworker.addEventListener('message', (result) => { console.log(result); });
Dworker.receive('message', (result) => { console.log(result); });
Step-by-Step Solution
Solution:
  1. Step 1: Recall Node.js worker event syntax

    Node.js workers use the on method to listen for events.
  2. Step 2: Identify the correct event and method

    The event to receive data is message, and the syntax is worker.on('message', callback).
  3. Final Answer:

    worker.on('message', (result) => { console.log(result); }); -> Option A
  4. Quick Check:

    worker.on('message') = A [OK]
Quick Trick: Use worker.on('message', callback) to get results [OK]
Common Mistakes:
  • Using non-existent methods like listen or receive
  • Confusing browser event syntax with Node.js
  • Using addEventListener which is not in Node.js workers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes