{"canonical_url":"https://engineer.company/glossary/javascript/","content_markdown":"# JavaScript\n\n## What it is\n\nJavaScript is a dynamically typed programming language, standardised as ECMAScript, that every web\nbrowser can execute and that also runs on servers and build machines through runtimes such as\nNode.js. People shorten it to JS. The standard's yearly editions are named ES2015, ES2024 and so on,\nthe older numbering (ES5, ES6) is still heard, and \"vanilla JavaScript\" means the language with no\nframework on top. Apart from the name and some curly-brace syntax, it shares little with Java.\n\nBrendan Eich wrote the first version at Netscape, and it shipped in the Navigator 2.0 browser. Ecma\nInternational adopted the first edition of the standard, ECMA-262, in June 1997, and its committee\nTC39 has published a new edition every year since ECMAScript 2016. A proposal joins the\nspecification only at stage 4 of the committee's process, which requires implementations that\nalready ship, so the text and the engines seldom disagree for long.\n\nThe language says very little about the outside world. ECMA-262 defines the syntax, the types,\nobjects, promises and modules, and leaves input and output to whatever hosts it. In a browser that\nenvironment is the web platform: the document, events, timers and network requests, specified mostly\nby the HTML Standard and its sibling standards. Node.js supplies files, sockets and processes\ninstead. That split explains a common surprise: code can be perfectly valid JavaScript and still\nbreak when it moves from a page to a server, because the language travelled and its environment\nstayed behind.\n\nIn a browser, a page's scripts share one main thread with layout, painting and input. A task runs to\ncompletion before the browser can respond to the next click. Promises and `async` functions keep\nwaiting off that thread, while computation stays on it unless it is moved to a Web Worker. Numbers\nare IEEE 754 double-precision values, so whole numbers are exact only up to 2^53 − 1, and anything\nlarger needs `BigInt`.\n\n## Why it matters\n\nThe real decision is how much of it to send to the people reading your site. JavaScript is the\nlanguage that makes a page behave without a round trip to a server, and every kilobyte of it is\ndownloaded, parsed, compiled and run on a device you do not control. The bundle that feels instant\non a developer's laptop can hold a mid-range phone busy for seconds, and the reader pays for that in\nbattery and patience.\n\nScript is also where a page is most exposed. An attacker's script, if it executes,\nruns with the page's authority: it can read what the reader types and send it\nanywhere the page may send. That is the risk Content Security Policy exists to\ncontain. Shipping no executable JavaScript removes the site's own browser scripts\nas an attack surface; untrusted input still needs safe handling and a restrictive\npolicy. The package ecosystem adds a second exposure. A typical front-end build\npulls in hundreds of transitive dependencies, and each one is code that executes\nwith the same rights as yours.\n\nThe other side of the ledger is real. Running one language on both sides of a system lets the\nbrowser and the server share a validation rule or a data shape, and some products need a lot of\nscript: offline state, drag and drop, maps, live collaboration. The useful question is asked per\nfeature: does this need to happen in the reader's browser without asking a server? If it does not,\nrender it on the server or at build time and ship HTML.\n\nThe related choice is JavaScript vs TypeScript. TypeScript adds a type checker and a build step and\ncompiles back to plain JavaScript. For a codebase several people change every week, the checker\nusually pays for itself; for a hundred-line enhancement on a static page, JavaScript and a strict\nlinter are enough.\n\n## What it looks like in practice\n\nThis site delivers static pages without executable JavaScript to its readers. Its search\ncode is retained but disabled; JavaScript still runs in the build and checking tools.\nThree pages show the earlier browser exception and the work done outside the browser.\n\nAn earlier three-language version had no runtime backend and delivered a single\nfirst-party script. [The Hugo build\nrecord](/portfolio/built-a-multilingual-hugo-site-in-3-languages/) describes that scoped\nexception: a portfolio filter whose controls stayed hidden until the script ran. Its 108\ntemplate files, including 53 partials and 18 shortcodes, did their work when the site\nwas built. The record also names the cost of that choice at the time: interactive\nfeatures had to be resolved in the build, and a search index was costed and parked\nrather than shipped. Those figures and that exception describe the earlier\nimplementation, not the code now delivered to a reader.\n\nThe same content is published over Gemini and Gopher, two protocols with no place for a script at\nall.\n[One build wrote 777 documents in each format at the recorded implementation stage](/portfolio/mirrored-the-site-to-gemini-and-gopher/)\nfrom the same source as the pages. A separate build comparison confirmed zero HTML bytes changed\nwhen those output formats were added; the result does not cover later editorial or visual changes.\nThe site argues that a document does not need a megabyte of script to be read, and a format that\ncannot hold one is the plainest way to show it.\n\nMost of the JavaScript here lives in the tooling. At the implementation stage recorded by the linked work, the site's quality gate\ncomprised thirty-two scripts and 10,242 lines of JavaScript, then the largest body\nof code in the repository. For a while it was the one body of code that nothing\nformatted, linted or type-checked.\n[Bringing it under a formatter and a linter](/portfolio/linted-the-10242-line-quality-gate-itself/)\nbegan by fitting the formatter to the code: the repository's four-space default would have rewritten\n2,173 lines of the largest checker, and a two-space override for those files left 38 lines of real\ndrift. The linter then raised 13 findings, and all 13 were fixed with none suppressed. A bug in a\nchecker shows itself as a check that passes when it should fail, so the gate's own code gets the\ntreatment it gives everything else.\n\n## Where it goes wrong\n\nThe failures below follow from how the language is built, and each has a known remedy.\n\n**The page renders, then ignores taps for a second or more.** A long task, such as hydrating a large\nbundle, parsing a big JSON response or sorting thousands of rows, holds the one thread that handles\ninput. Ship less code for the first interaction by splitting bundles per route and deferring the\nrest, break long work into pieces that yield back to the event loop, and move heavy computation into\na Web Worker. Measure on a slow phone rather than on the laptop that wrote the code.\n\n**Prices and identifiers come out slightly wrong.** Every number is a binary floating-point value,\nso decimal fractions round and very large integers collapse into their neighbours. A 64-bit database\nkey sent as a JSON number is the usual victim:\n\n```js\n0.1 + 0.2 === 0.3; // false\nNumber.MAX_SAFE_INTEGER; // 9007199254740991\n9007199254740993 === 9007199254740992; // true\n```\n\nKeep money in integer minor units such as cents, send large identifiers as strings, and use\n`BigInt` where the arithmetic has to be exact.\n\n**A comparison lets the wrong value through.** The `==` operator converts its operands before\ncomparing them, so `\"\" == 0` and `\"0\" == false` are both true. Use `===` throughout and let the\nlinter's `eqeqeq` rule enforce it, so the conversion is something the code asks for out loud.\n\n**Text from a user ends up running as code.** Assigning untrusted text to `innerHTML`, building\nmarkup by string concatenation or handing input to `eval` turns data into script. Write text with\n`textContent`, send a Content Security Policy that admits scripts only by nonce or hash, and keep\nthe dependency list short and pinned in a lockfile, reading what each update pulls in.\n\n**Code that works in the browser crashes on the server.** The language moved and its environment did\nnot: `window` and `document` exist only in a browser, and Node.js reads a file as CommonJS or as an\nES module depending on settings the browser never sees. Keep runtime-specific calls at the edges,\nset `\"type\": \"module\"` explicitly in `package.json`, and run each piece of code in the environment\nit will actually run in.\n\n## Further reading\n\n- [ECMAScript Language Specification](https://tc39.es/ecma262/) — the living draft of ECMA-262,\n  the text every engine implements, updated as proposals reach stage 4.\n- [The TC39 Process](https://tc39.es/process-document/) — the stages a proposal passes through\n  before it becomes part of the language, and what each one demands.\n- [ECMA-262 at Ecma International](https://ecma-international.org/publications-and-standards/standards/ecma-262/)\n  — the published yearly editions, for when a project has to name the version it targets.\n- [HTML Standard: event loops](https://html.spec.whatwg.org/multipage/webappapis.html#event-loops)\n  — how a browser schedules tasks, microtasks and rendering around a page's scripts.\n- [HTML Standard: the script element](https://html.spec.whatwg.org/multipage/scripting.html#the-script-element)\n  — classic and module scripts, and how `async` and `defer` change when they run.\n\n\u003chttps://engineer.company/glossary/javascript/\u003e\n","date_modified":"2026-11-08T11:12:58Z","description":"How much JavaScript a page should ship, where the language runs besides the browser, who standardises it, and how it fails on sites and in tooling.","formats":{"gemtext":"https://engineer.company/glossary/javascript/index.gmi","gopher":"https://engineer.company/glossary/javascript/gophermap","html":"https://engineer.company/glossary/javascript/","json":"https://engineer.company/glossary/javascript/index.json","markdown":"https://engineer.company/glossary/javascript/index.md","pdf":"https://engineer.company/glossary/javascript/index.pdf"},"kind":"page","language":"en","title":"What is JavaScript?","url":"https://engineer.company/glossary/javascript/","version":1}