# JS is compiled

[JS](https://lochiwei.gitbook.io/web/js) ⟩ [concepts](https://lochiwei.gitbook.io/web/js/concept) ⟩ [compiler](https://lochiwei.gitbook.io/web/js/compile) ⟩ JS is compiled

{% hint style="info" %}
JavaScript code is <mark style="color:yellow;">**compiled**</mark> first, and then <mark style="color:yellow;">**execute**</mark>.
{% endhint %}

{% tabs %}
{% tab title="💈範例" %}
{% hint style="danger" %}
⛔ <mark style="color:red;">**SyntaxError**</mark>: <mark style="color:yellow;">**unexpected token**</mark> "xxx"
{% endhint %}

* replit：[JS is a compiled language](https://replit.com/@pegasusroe/JS-is-a-compiled-language#index.js)

```javascript
var greeting = "Hello";
console.log(greeting);   // ⭐️ this line doesn't have a chance to run❗ 

greeting = ."Hi";        // ⭐️ error occurred in the "tokenizing" stage
//         ↑             //    of compilation❗
//         ↑
// ⛔ SyntaxError: unexpected token .
```

{% 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. 1: What's the Scope?](https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/ch1.md#chapter-1-whats-the-scope)
  {% endtab %}
  {% endtabs %}
