A file with .js extension contain javascript code. It allows javascript code to be written in a single javascript file and can be used with multiple web pages. Multiple external javascript file can used in a website.

Example

<script src="your_script_file.js"></script>

Advantages

  1. No code duplicacy and repetition.
  2. Error finding and debugging is easier
  3. Save lot of time.
  4. Makes code maintainable, clean and easy to read.
  5. Seprates HTML and Javascript Code.

How to use or reference an external javascript file

<!DOCTYPE html>
<html>
<body>
<script src="your_script_file.js"></script>
</body>
</html>

Where to put javascript external file

External Javascript file can be placed in head or body section as required.