🔰browser-specific features
JS ⟩ module ⟩ ES module ⟩ browser-specific
When using modules, HTML page shows up as it loads, and modules run after that, so the user may see the page before JS code is ready❗️
<script type="module">
// ⭐️ modules are deferred, can 'see' elements below.
console.lot(button); // HTMLButtonElement
</script>
<script>
// ⭐️ regular scripts run immediately, CAN'T 'see' elements below.
console.log(button); // ⛔️ ReferenceError: `button` not defined.
</script>
<button id="button">Button</button><!--
all dependencies fetched, and the script runs,
doesn't wait for the document or other <script>.
-->
<script async type="module">
import {counter} from './analytics.js';
counter.count();
</script>JS.info ⟩ Async works on inline scripts
Last updated
Was this helpful?