How to Create a Js File

By Maureen Bruen

To create a Js (JavaScript) file simply remove the SCRIPT tags and save the JavaScript code with a .js extension using Notepad. This allows you to call the JavaScript when needed, instead of having the JavaScript code typed out in the HTML (Hyper Text Markup Language) code. The SCRIPT tags are removed to make the .js file and are added to the HTML file of a web page with a reference to the .js file created. This method can be used with any web page.

Step 1

Launch "Notepad."

Step 2

Type out your code. For example: alert("You are running the " + navigator.appName + " browser."). This is the JavaScript without the SCRIPT tags. Before the SCRIPT tags are removed the JavaScript looks like the following:

Step 3

Click "File," "Save" and the "Save As" dialog box is displayed.

Step 4

Type "myfile.js" and click the "Save" button. Now you have created a .js file. By adding,