.js File Extension
.js file is, how to open JavaScript source safely, how Poly supports it, and when .mjs, .cjs, or TypeScript may fit better. File extension details for .js
Full Support| File type | JavaScript source file |
|---|---|
| MIME type | |
| Encoding | Unicode source text, normally UTF-8 |
| Operating systems | Windows, macOS, Linux, ChromeOS |
| Opens with | Visual Studio Code, WebStorm, Sublime Text, Node.js |
| Poly support | Yes. Poly recognizes .js files as readable JavaScript source. |
| Indexed by Poly | Yes. Poly indexes readable source for exact and semantic search. |
| Preview in Poly | Yes. .js files open in Poly's read-only code editor. |
| Poly agent | Yes. The Poly agent can read and reason about the source without executing it. |
What kind of file is a .js?
A .js file normally contains JavaScript or ECMAScript source code. It is plain text rather than compiled machine code, so you can inspect it in any text editor. For web delivery, the current registered MIME type is text/javascript. The older application/javascript type is now an obsolete alias.1
There is no magic byte sequence that proves a file is JavaScript. IANA lists no signature for the type, and the same text could resemble JSON, TypeScript, or another language.1 Check the extension, declared MIME type, surrounding project, and source itself rather than trusting the name alone.
program.txt to program.js does not validate or translate it. Renaming a TypeScript file to .js also does not remove its type syntax.How do I open a .js on my computer?
Open .js files on Windows, macOS, Linux, or ChromeOS with a code editor such as Visual Studio Code, WebStorm, or Sublime Text. A basic text editor works for a quick inspection. Syntax highlighting, code navigation, and diagnostics make a code editor more useful for larger files.
A browser usually loads .js as part of a web page. Node.js can run compatible files from a terminal, but the suffix alone does not settle which module system applies. In Node.js, the nearest package.json and its "type" field can make .js behave as an ECMAScript module or CommonJS; explicit .mjs and .cjs suffixes remove that ambiguity.2
.js file merely to see what it does. JavaScript can access data and capabilities granted by its browser, server, or automation host. Inspect imports, network requests, dynamic evaluation, and requested permissions first.Poly support for .js
Poly recognizes .js as JavaScript source and opens it in a read-only code editor with syntax highlighting, word wrap, and in-file search. Its readable content is available to exact and semantic search. The Poly agent can summarize the file, explain functions, or reason about the source.
Poly does not execute the program, install its dependencies, or automatically follow imported modules. That makes preview useful for inspection, but it is not a security verdict and cannot reveal every behavior of obfuscated or generated code.
History of .js
JavaScript first appeared in Netscape Navigator. Ecma International began standardizing the language in November 1996 and adopted the first ECMA-262 edition in June 1997.3 The short .js convention became the familiar suffix for JavaScript source on the web and is registered for text/javascript alongside .mjs.1
The media-type story changed over time. RFC 4329 once favored application/javascript, but deployed web practice continued to favor text/javascript. RFC 9239 standardized that reality in 2022, making text/javascript the common type and marking historical alternatives obsolete.4
Working with .js and alternatives
Choose the suffix and source language based on the runtime and workflow:
| Choice | Best fit | Important distinction |
|---|---|---|
.js | Browser scripts and convention-based Node.js projects | Module mode can depend on host configuration |
.mjs | Explicit ECMAScript modules | Signals Module grammar where extensions decide it |
.cjs | Explicit Node.js CommonJS | Signals CommonJS regardless of package type |
.ts | Projects that want static type checking | Must usually be compiled or transformed for JavaScript runtimes |
RFC 9239 explains that content or MIME type alone cannot always distinguish ECMAScript's Script and Module grammars.4 Keep package.json, build settings, and imports with the source when sharing a project. If you compile TypeScript, bundle modules, or transpile newer syntax, the generated .js is a new artifact, not the result of renaming the original file.
For websites, serve .js with Content-Type: text/javascript. Ordinary <script> elements do not need a type="text/javascript" attribute because JavaScript is the default, while external module responses are subject to MIME checks.5
Footnotes
- Internet Assigned Numbers Authority. text/javascript Media Type Registration. ↩ ↩2 ↩3
- Node.js. Modules: Packages. ↩
- Ecma International. ECMA-262, 1st Edition. June 1997. ↩
- Miller, M., Borins, M., Bynens, M., and B. Farias. RFC 9239: Updates to ECMAScript Media Types. Internet Engineering Task Force, May 2022. ↩ ↩2
- WHATWG. HTML Standard: The
scriptElement. ↩