Bird
0
0

Which of the following is the correct way to create a new Worker in Node.js using the worker_threads module?

easy📝 Syntax Q3 of 15
Node.js - Worker Threads
Which of the following is the correct way to create a new Worker in Node.js using the worker_threads module?
Aconst worker = Worker.create('./worker.js');
Bconst worker = new Worker('./worker.js');
Cconst worker = new Thread('./worker.js');
Dconst worker = worker_threads.spawn('./worker.js');
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct Worker instantiation syntax

    The Worker class is instantiated with 'new Worker(path)' from 'worker_threads'.
  2. Step 2: Identify incorrect options

    Methods like create(), spawn(), or class Thread do not exist in worker_threads.
  3. Final Answer:

    const worker = new Worker('./worker.js'); -> Option B
  4. Quick Check:

    Worker creation syntax = new Worker(path) [OK]
Quick Trick: Use 'new Worker(path)' to create a worker thread [OK]
Common Mistakes:
  • Using non-existent methods like create() or spawn()
  • Confusing Worker with Thread class

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes