SUPER IMPORTANT NOTE: When using the script tag, it is mandatory that you use the closing </script> tag just as it appears. Don’t try to use the “short-cut” approach like this <script type="text/javascript" />. This will cause issues and will likely end in your script NOT being imported at all.

Alright, having said that, let’s put all of this code together and import this JavaScript file into our simple HTML page!

It’s usually recommended that you put your script tags into the head area of your page like so:

Embedding JavaScript Code in Your HTML Page

There is also a second way to include JavaScript code in your HTML files, and that’s by directly embedding the JS code itself.

This method is nearly identical to the one above, and thus the same rules from above apply here. You still need to use the proper closing </script> tag when embedding JavaScript code.

The only difference when embedding JavaScript code is that you don’t specify a src property, as you’re not importing the code from an external file, so there’s no purpose to trying to specify the source of the code right?