js
What is a .js file?
text/javascript
JavaScript (.js) is a plain-text source file for the JavaScript language: the scripting language of the web, also used server-side via Node.js. It is dynamically typed and event-driven, with first-class functions, prototypes, and (in modern syntax) modules, classes, and async/await.
How to use a .js file
Use an example .js file to test syntax highlighters, linters (ESLint), formatters (Prettier), bundlers, and JavaScript parsers, or as editor and diff-viewer fixtures.
Download example .js files
- JavaScript: Hello WorldThe classic hello-world in modern JavaScript: a minimal function calling console.log, for testing highlighters, Node, and JS parsers.
- JavaScript: To-do list (class, private fields, async)A realistic JavaScript snippet with an ES class, private #fields, arrow functions, template literals, a getter, and async/await, for testing highlighters, ESLint, Prettier, and bundlers.
- JavaScript: Intentionally Invalid SyntaxIntentionally corrupt JavaScript object literal, labelled invalid for error handling. Labelled intentionally invalid in title and description.
- Code Config: Eslint Flat SnippetTiny SAMPLE tooling config snippet (eslint-flat-snippet) for editor/linter harnesses.
- Javascript Lint Invalid: Var Shadow InvalidIntentionally lint-bait SAMPLE javascript snippet (var-shadow-invalid) for rule-engine tests.
- Javascript Lint Invalid: Eqeqeq InvalidIntentionally lint-bait SAMPLE javascript snippet (eqeqeq-invalid) for rule-engine tests.
- Service Worker (sw.js)A sample cache-first service worker handling install, activate, and fetch events with an offline fallback, for testing service-worker registration, JS parsers, and PWA tooling.
- Service Worker: Offline Shell SAMPLECache-first SAMPLE service worker for PWA offline-shell registration tests.
and 3 more in the library.