# Adding JS to HTML — JavaScript Fundamentals: From Syntax to Async

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

> Add JavaScript to a page with script tags and choose between defer and async for faster loading.

## 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>
```
