Introduction
A .js file holds JavaScript, the programming language of web pages, as
plain text. Browsers run it in pages, and runtimes such as Node.js, Deno and Bun run it
on servers and in the terminal.
Two other extensions say which module system a file uses in Node.js:
.mjs for an ECMAScript module (import and
export) and .cjs for a CommonJS module
(require and module.exports).
The pages listed below are a complete reference to the language. They follow ECMA-262, the ECMAScript language specification, and name its clauses by title. They cover the published editions up to ES2026, and mark features that are only in the current draft.
Structure
A JavaScript file is plain text, normally UTF-8, with no header. A file is either a classic script or a module, and the text alone does not always say which. See File structure for how hosts choose, the extensions, the hashbang line, encoding and directives.
Language reference
The reference is split into these pages.
- File structure – scripts and modules,
.js,.mjsand.cjs,package.json"type", the hashbang line, encoding and directives - Lexical structure – tokens, comments, automatic semicolon insertion, keywords, numeric, string and template literals, and regular expression versus division
- Types – the primitive types, Object,
typeof, the conversion operations and the equality algorithms - Variables and scope –
var,letandconst, hoisting, the temporal dead zone, closures and the global object - Expressions – the full operator table, destructuring, spread, optional chaining and nullish coalescing
- Statements – blocks, loops,
switch, labels,try,withandusing - Functions – declarations, arrows, the
thisbinding, parameters andarguments - Objects and prototypes – property descriptors, the prototype chain, getters and setters,
ProxyandReflect - Classes – fields, private names, static blocks and inheritance
- Iterators and generators – the protocols, iterator helpers, generators and async iteration
- Async – promises,
asyncandawait, jobs and the event loop - Modules –
import,export, dynamic import, import attributes, top-levelawaitand CommonJS interop - Regular expressions – the full syntax and flags
- Built-ins – the standard global objects and the edition that added each
- Strict mode – what it restricts and changes
- Versions – what each edition from ES1 to ES2026 added, and the current draft
Regular expressions and division in the viewer
A / is a division when the token before it is a value and starts a regular
expression when an operand is expected. The viewer keeps a stack of the open
parentheses and braces to decide.
- After
a++ora--a/divides, after++athe next name is the value. - After the
)that closes the head of anif,while,for(alsofor await) orwith, a/starts a regular expression:if (x) /re/.test(y). After any other)it divides. - After a
}that closed a block (a statement block, anifortrybody, a function or class declaration, an arrow function body) a/starts a regular expression. After a}that closed an object literal, a function expression or a class expression it divides. A function or class is an expression where a value is expected (after=,(,,,return) and a declaration at the start of a statement. - A
${ }in a template literal starts again with empty stacks, so the code inside it, nested templates included, is judged on its own.
TypeScript and ActionScript use the same scanner.
Not described
Known, not yet covered
- Reference: the pages follow ECMA-262 only. The built-ins page names the global objects and the edition that added each member, but does not describe how each method behaves.
Intl(ECMA-402) andTemporal(stage 4, not yet in the text) are only named there. - Reference: what runs beside the language is not described: the browser’s DOM and Web APIs, the Node.js, Deno and Bun libraries, JSX and other syntax extensions that a build step removes, WebAssembly’s JavaScript interface, source maps and minification. TypeScript has its own pages.
- Viewer: the choice between a regular expression and a division is still a heuristic, not the grammar. It looks only at the nesting of brackets, and at the line before a
{: a comment between a function head and its{, a TypeScript type literal in a return type, or ado ... while (x)loop followed by a regular expression can be read the wrong way, and a}closing an object literal that starts a statement is read as a block. - Viewer: JSX is not understood (the viewer opens only
.js,.mjsand.cjs, not.jsx), so tags in a file are left as plain text with their braces scanned as code. Words that are names as often as not (of,get,set,from,as,using) are left plain,asyncis coloured wherever it appears, and private names (#p) and global objects such asconsoleorglobalThisare plain; only a short list of constructors (Map,Promise,Mathand others) is coloured as types. - Viewer: the file is not parsed: no scope, strict-mode, early-error or module-resolution problems are reported,
importpaths are not followed, and the viewer does not tell a script from a module. Only the first 1 MiB of a file is read and coloured.
Links
Software
- Google Chrome – web browser that runs JavaScript in pages (Windows, macOS, Linux, mobile)
- Firefox – web browser that runs JavaScript in pages (Windows, macOS, Linux, mobile)
- Safari – Apple’s web browser (macOS, iOS)
- Node.js – runtime for JavaScript on servers and the command line (Windows, macOS, Linux)
- Deno – JavaScript and TypeScript runtime (Windows, macOS, Linux)
- Bun – fast JavaScript runtime and toolkit (Windows, macOS, Linux)
- Visual Studio Code – free code editor with built-in JavaScript support (Windows, macOS, Linux)
- WebStorm – JetBrains’ development environment for JavaScript (Windows, macOS, Linux)
Developers
Reference
- ECMAScript language specification – ECMA-262, the current draft
- JavaScript – guide and reference on MDN Web Docs