files/en-us/web/api/worker/terminate/index.md
{{APIRef("Web Workers API")}}{{AvailableInWorkers("window_and_worker_except_service")}}
The terminate() method of the {{domxref("Worker")}} interface immediately terminates the {{domxref("Worker")}}. This does not offer the worker an opportunity to finish its operations; it is stopped at once.
terminate()
None.
None ({{jsxref("undefined")}}).
The following code snippet shows creation of a {{domxref("Worker")}} object using the {{domxref("Worker.Worker", "Worker()")}} constructor, which is then immediately terminated.
const myWorker = new Worker("worker.js");
myWorker.terminate();
[!NOTE] DedicatedWorkers and SharedWorkers can also be stopped from the {{domxref("Worker")}} instance using the {{domxref("DedicatedWorkerGlobalScope.close()")}} or {{domxref("SharedWorkerGlobalScope.close()")}} methods.
{{Specifications}}
{{Compat}}