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
- No code duplicacy and repetition.
- Error finding and debugging is easier
- Save lot of time.
- Makes code maintainable, clean and easy to read.
- 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.