# web worker

[JS](https://lochiwei.gitbook.io/web/js) ⟩ [browser](https://lochiwei.gitbook.io/web/browser) ⟩ [web API](https://lochiwei.gitbook.io/web/browser/api) ⟩ web worker

{% hint style="success" %}
(a JS [env](https://lochiwei.gitbook.io/web/js/concept/env "mention")) an <mark style="color:yellow;">**extension**</mark> on top of [..](https://lochiwei.gitbook.io/web/browser "mention")-JS behavior, which allows a <mark style="color:yellow;">**JS file**</mark> to run in a completely <mark style="color:yellow;">**separate thread**</mark> from the thread that's running the main JS program.
{% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="warning" %} <mark style="color:purple;">**Web Worker**</mark> code&#x20;

* <mark style="color:red;">**does not**</mark> have <mark style="color:yellow;">**access**</mark> to the [dom](https://lochiwei.gitbook.io/web/browser/dom "mention"). (<mark style="color:red;">**can't**</mark> access [window](https://lochiwei.gitbook.io/web/js/scope/global/object/window "mention"), for example)
* <mark style="color:red;">**does not**</mark> <mark style="color:yellow;">**share**</mark> the [global](https://lochiwei.gitbook.io/web/js/scope/global "mention") with the <mark style="color:yellow;">**main JS program**</mark>.
  {% endhint %}

{% hint style="success" %} <mark style="color:purple;">**Web Worker**</mark> code <mark style="color:green;">**do**</mark> have access to the following [](https://lochiwei.gitbook.io/web/browser/api "mention")：

* naviagtor
  {% endhint %}
  {% endtab %}

{% tab title="👥 相關" %}

* <mark style="color:purple;">**web worker**</mark> is a JS [env](https://lochiwei.gitbook.io/web/js/concept/env "mention").
  {% endtab %}

{% tab title="📗 參考" %}

* [ ] [ydkjs-scope-and-closures-v.2](https://lochiwei.gitbook.io/web/master/ref/book/you-dont-know-js-series-v.2/ydkjs-scope-and-closures-v.2 "mention") ⟩ Ch. 4 ⟩ [Web Worker](https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/ch4.md#web-workers)
* [ ] MakeUseOf ⟩ [An Introduction to JavaScript Web Workers](https://www.makeuseof.com/javascript-web-workers-introduction/)
  {% endtab %}

{% tab title="📘 手冊" %}

* [ ] [Web APIs](https://developer.mozilla.org/en-US/docs/Web/API) ⟩ [Worker](https://developer.mozilla.org/en-US/docs/Web/API/Worker)
  {% endtab %}

{% tab title="🚧" %}

* [ ] navigator
  {% endtab %}
  {% endtabs %}
