What Is a .JS File? (.js, .mjs, .cjs)
A .js file is a JavaScript source code file. Websites load JS files to add interactivity, and Node.js runs them as programs and tools on servers and computers. It is plain text you can read in any editor. Be careful: on Windows, double-clicking a .js file can run it as a script.
- Extension
- .js, .mjs, .cjs
- Full name
- JavaScript Source Code
- Type
- Code and web file
- MIME type
- text/javascript
- Developed by
- Brendan Eich at Netscape; standardized by Ecma International as ECMAScript
About JS files
JavaScript is the programming language of the web. Browsers download .js files referenced by web pages and run them in a sandbox. Outside the browser, Node.js, Deno and Bun run JavaScript for servers, command-line tools and build systems. The .mjs and .cjs extensions mark ES module and CommonJS files explicitly for Node.js. Minified production files, often named something.min.js, are compressed into a single unreadable line.
On Windows there is an important security catch. By default, double-clicking a .js file runs it with Windows Script Host, outside any browser sandbox, with access to files and the ability to download more programs. This is why malicious .js files inside ZIP email attachments are a common malware delivery method. Never double-click a .js file you were sent; open it in Notepad to read it instead.
JavaScript files are usually small, from a few lines to a few megabytes for bundled web apps. TypeScript (.ts) and JSX/TSX files compile down to plain .js. JSON looks similar but is data only, while a .js file is executable code.
What JS files are used for
- Interactive behaviour on websites
- Node.js servers, scripts and command-line tools
- Build configuration files (webpack.config.js, eslint.config.js)
- Browser extensions and bookmarklets
How to open a .js file
Windows
Right-click > Open with > Notepad or VS Code to read it safely. Do not double-click a .js file you do not trust, because Windows Script Host may run it.
Mac
Open it in TextEdit or VS Code to read. To run it, install Node.js and run node file.js in Terminal.
Linux
View it in any text editor; run it with node file.js once Node.js is installed.
Online / any browser
A browser runs JavaScript only when it is included in a web page; the developer tools console can run snippets.
How to convert a .js file
JavaScript is not usually converted, but tools transform it: a bundler such as esbuild or webpack combines and minifies files, and Prettier in VS Code reformats minified code to make it readable.
To view a .js file as text without any risk of running it on Windows, rename a copy to .txt or open it from Notepad's File > Open.
Changing the extension in the file name does not convert the file. See how to change a file extension for when renaming is safe.
Naming and renaming JS files
- Use lowercase with hyphens or camelCase consistently (date-utils.js or dateUtils.js); import paths are case-sensitive on Linux and macOS servers even when Windows forgives a mismatch.
- Keep .min.js for minified builds and never edit them directly; edit the source and rebuild.
- Do not rename config files such as webpack.config.js, vite.config.js or eslint.config.js, because the tools search for those exact names.
Renaming lots of .js files? See how to rename javascript files with ai, use the free online bulk renamer for patterns and numbering, or try File Renamer AI to name each file from what is inside it.
Related file types
A .ts file is one of two unrelated things: an MPEG transport stream video, used for broadcast TV recordings, streaming segments and camcorders, or a TypeScript source code file used by web developers. You can tell them apart by size and content: video files are large binary data, TypeScript files are small readable text.
A .json file is a plain text data file in JavaScript Object Notation, a lightweight format of names, values, lists and nested objects. It is the standard way web APIs exchange data and a common format for app settings, exports and configuration. Any text editor opens JSON, and browsers can display it nicely.
A .html or .htm file is a web page written in HyperText Markup Language. It is plain text with tags that describe headings, paragraphs, links, images and forms, which a web browser renders as a formatted page. Double-clicking an HTML file opens it in your default browser; any text editor can edit it.
A .py file is a Python script: a plain text file of Python source code that the Python interpreter runs. It is used for automation, data analysis, web back ends, machine learning and teaching. You can open and read any .py file in a text editor, but running one requires Python to be installed.
Frequently Asked Questions
Is it safe to open a .js file?
Reading it in a text editor is safe. On Windows, double-clicking can run it through Windows Script Host, so never double-click a .js file from an email or unknown download.
How do I run a .js file?
Install Node.js and run node filename.js in a terminal. Browser JavaScript runs when the web page that includes it loads.
What is the difference between .js and .json?
A .js file contains executable JavaScript code; a .json file contains only data in a format borrowed from JavaScript syntax.