How to Include a JavaScript File

To include a JavaScript file on a webpage, insert a <script> tag:

<!DOCTYPE html>
<html>
<head>
  <title>My Page</title>
  <script src="test.js"></script>
</head>
<body>
  Hi, here is some text.
</body>
</html>

where test.js file is a text file with some JavaScript in it, e.g.:

alert('hi there');

Next: Conditional 'if' statements in JavaScript

Comments

Leave a comment

What color are green eyes? (spam prevention)
Submit
Code under MIT License unless otherwise indicated.
© 2020, Downranked, LLC.