# Adding JS to HTML — JavaScript

Source: https://www.geekswithgeeks.com/en/javascript/js-adding-js-to-html

> Script tag placement, and defer vs async.

## The <script> tag

Link an external file, or write JS inline between the tags.

```html
<script src="app.js"></script>

<script>
  console.log("Inline JS");
</script>
```

## Where to place it

Put `<script>` just before `</body>`, or use `defer` in `<head>` — both let the HTML load first so the page isn't blocked.

## defer vs async

`defer` runs scripts in order after parsing finishes; `async` runs as soon as it's downloaded — order isn't guaranteed.

```html
<script src="a.js" defer></script>
<script src="b.js" async></script>
```
