Ask coding questions

← Back to all posts
What is having multiple javascript files?
h
codeitfast (59)

I was wondering what it means to have multiple JavaScript files. How do they run together and in which order do they run? Also, can you run specific JavaScript files through JavaScript?

Thanks!

Answered by Coder100 (18146) [earned 5 cycles]
View Answer
Comments
hotnewtop
Coder100 (18146)
  1. multiple js files are a great way to make your code clean.

Here is an example:

<script src="main.js"></script>
<script src="lib.js"></script>

they run in the order you specify they script tags.

  1. you sort of can
    step 1: make your js file a module
<script type="module" src="script.js"></script>

then using the import syntax

import { something } from "./other.js";

https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/import