How to open JavaScript files without running it

A JavaScript file is a regular computer file that ends with the .js extension.

Windows operating system usually runs the file instead of opening it because the .js extension is shared with the JScript language, which is an implementation of ECMAScript developed by Microsoft.

When you double click on a .js file, the following error usually occurs:

To open a JavaScript file without executing it on Windows, you need to right-click on the .js file and open the context menu:

JavaScript code is written in plain text, so you can use any popular file readers (Notepad and TextPad) or word processors (Microsoft Word or Apple Pages) to open JavaScript files.

You only need to right-click on the JavaScript file and select the Open With.. option from the context menu to open the file with an editor that you prefer.

But since Notepad and Microsoft Word are not dedicated source code editors, the code inside your JavaScript file will appear just like a regular text without any highlights:

Generally, a dedicated source code editor is used by programmers when editing source code because the software provides many feature that makes coding easier.

One of them is called syntax highlighting, where your JavaScript code will appear in different colors and fonts according to the use of the keywords

An example of syntax highlighting is as follows:

let name = "Nathan" + "Sebhastian";
console.log(name);

let age = 10 + 6;
console.log(age);

function myFunction(a, b) {
  if (a == "Johnny" && b == "English") {
    console.log("Welcome, Britain's greatest agent!");
  } else {
    console.log("Identification failed.");
  }
}
myFunction("Johnny", "English");

As you can see from the example above, a dedicated source code editor will help you to spot specific parts of your code easier by using different colors and (sometimes) fonts than using a regular text editor.

If you want to use a source code editor to open JavaScript files, then I’d recommend you to download Visual Studio Code (VSCode for short)

VSCode is a dedicated source code editor developed by Microsoft and used by professional software developers across the globe. It’s available for popular operating systems like Windows, MacOS, and Linux.

VSCode can also run your JavaScript code locally without using the browser or NodeJS server, so you can test your JavaScript file execution and see if it’s working as you intended.

Other popular source code editor include Sublime Text and Atom, but personally I just use VSCode for developing JavaScript application.

Feel free to use any source code editor that you like.

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.