What is a .js file?
JavaScript · Code and data · Netscape (Brendan Eich) · 1995
JS is a JavaScript source file, the scripting language that runs in every web browser and, via Node.js, on servers and the desktop too. A page's <script> tag loads and runs one to add interactivity, from a button click to an entire application's logic.
What is a .js file used for?
A .js file is source code in JavaScript. In a browser, a <script> tag loads and executes it against the current page, which is how a page goes from static HTML to something interactive.
The same language now runs outside the browser too, most notably through Node.js, which is why .js files also drive servers, command-line tools and desktop apps built with frameworks like Electron.
The related .mjs extension marks an ES module, JavaScript's standard mechanism for splitting code into files that explicitly import and export from each other. A plain .js file is treated as a classic script unless the surrounding project configures it otherwise.
Being plain text, any code editor opens a .js file, and a browser's developer tools let you inspect, and step through, the exact script a page is running.
How to open a .js file
The .js format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list.
Windows
- VS Code
- Notepad++
- any browser (dev tools)
macOS
- VS Code
- any browser (dev tools)
Linux
- VS Code
- any browser (dev tools)
Web
- Every browser runs it; dev tools show the source
How to convert a .js file
You can convert a .js file to Not convertible using a conversion tool or the export menu of an app that opens it.
.js file signature (magic bytes)
Programs recognise a .js file by the bytes at the start of the file, not by its name. These are the signatures for JS.
| Hex signature | Offset | Note |
|---|---|---|
| (no fixed signature) | 0 | plain text; no fixed signature |
See the full magic-numbers reference for every format.
Frequently asked questions
What is a .js file?
JS is a JavaScript source file, the scripting language that runs in every web browser and, via Node.js, on servers and the desktop too. A page's <script> tag loads and runs one to add interactivity, from a button click to an entire application's logic.
How do I run a .js file?
In a browser, it runs automatically when a page's <script> tag loads it, or you can paste it into the browser console. Outside a browser, run it with Node.js from a terminal: node file.js.
What is the difference between .js and .mjs?
Both hold JavaScript, but .mjs explicitly marks the file as an ES module using import and export, while a plain .js file is treated as a classic script unless the project's configuration says otherwise.
Related formats
Sources
Details on this page were checked against authoritative references: