1---2name: neo-javascript3description: Use this skill when writing, reviewing, debugging, or modernizing JavaScript across browser, Node.js, and pure JS projects. Trigger for ES module/CommonJS issues, async patterns, functional array/set/iterator code, DOM/runtime behavior, or version-aware ECMAScript syntax.4---56# Modern JavaScript (ES6+) Expert Skill78## Trigger On9- The user asks to write, debug, refactor, or review JavaScript code.10- The project directory contains `*.js`, `*.mjs`, or JavaScript configuration files (e.g., `eslint.config.js`, `vite.config.js`).11- HTML files (`*.html`) or Razor views (`*.cshtml`) contain inline `<script>` blocks or reference external `.js` files via `<script src="...">`.12- The target runtime is a modern browser (Chrome 80+, Firefox 78+, Safari 14+) or a pure JS environment.13- Code modernization is needed (e.g., converting `var` to `const`/`let`, callbacks to `async`/`await`, legacy scripts to ESM).1415## Workflow161. **Perceive (Environment Awareness):**17 - Inspect ESLint / Biome configuration to identify the project's `ecmaVersion` and coding conventions.18 - Determine runtime target: browser (check for DOM APIs, bundler config like `vite.config.js`, `webpack.config.js`).19 - Detect JavaScript embedded in HTML (`*.html`) or Razor views (`*.cshtml`): identify inline `<script>` blocks and external `<script src="...">` references. For `.cshtml` files, note the interplay with Razor syntax (`@` directives, `@section Scripts`).20 - Identify the effective ES version upper limit based on the runtime/transpiler configuration (e.g., Babel targets, TypeScript `target`, browserslist). For inline scripts without a build pipeline, default to the browser's native ES support.212. **Reason (Planning Phase):**22 - Evaluate the modernization level of the current code to determine the refactoring strategy.23 - In environments targeting older runtimes (e.g., IE11 via Babel), avoid using features without polyfill support, but prioritize using `const`/`let`, arrow functions, and template literals.24 - In modern environments (modern browsers), actively adopt new features to reduce boilerplate code.25 - Be aware of browser-specific concerns (DOM manipulation, Web APIs, rendering performance).263. **Act (Execution Phase):**27 - Write high-quality code using modern syntax to improve readability and maintainability.28 - Implement immutable data patterns (spread operators, `Object.freeze`, `structuredClone`, immutable array methods).29 - Utilize `async`/`await` and `Promise` composition for asynchronous operations.30 - Prefer ESM (`import`/`export`) as the standard module system.314. **Validate (Standard Validation):**32 - Validate strict equality (`===`) usage and absence of `var` declarations.33 - Check if asynchronous operations correctly handle errors (`try`/`catch` around `await`, `.catch()` on Promises).34 - Ensure code avoids common security pitfalls (no `eval()`, no prototype pollution, no `innerHTML` with unsanitized input).35 - Verify naming conventions follow community standards (camelCase for variables/functions, PascalCase for classes).3637## Feature Roadmap (ES6 - ES2025+)3839### ES6 & ES2016-ES2019 (Origin)40- **Arrow Functions:** `(a, b) => a + b` concise function syntax with lexical `this` binding.41- **`let` / `const`:** Block-scoped variable declarations replacing `var`.42- **Template Literals:** `` `Hello, ${name}!` `` for string interpolation and multi-line strings.43- **Destructuring:** `const { id, name } = user;` extract values from objects and arrays.44- **Default / Rest / Spread:** Default parameters, `...rest` parameters, and `...spread` for arrays/objects.45- **Classes:** `class` syntax for prototype-based inheritance with `constructor`, `extends`, and `super`.46- **Promises:** `new Promise((resolve, reject) => ...)` for asynchronous flow control.47- **Modules:** `import` / `export` for modular code organization (ES Modules).48- **Symbol / Map / Set:** New primitive type and collection data structures.49- **String Methods (ES6):** `includes()`, `startsWith()`, `endsWith()` for easier string searching.50- **Array Methods (ES6):** `Array.from()`, `Array.of()`, `find()`, `findIndex()` for enhanced array manipulation.51- **Number/Math Methods (ES6):** `Number.isInteger()`, `Number.isNaN()`, `Math.trunc()`, `Math.sign()`.52- **Generators & Iterators:** `function*` and `for...of` for lazy iteration.53- **`async` / `await` (ES2017):** Syntactic sugar for Promise-based asynchronous code.54- **Object.values / Object.entries (ES2017):** Iterate over object values and key-value pairs.55- **Rest / Spread Properties (ES2018):** `{ ...obj }` for object shallow cloning and rest extraction.56- **`Promise.finally` (ES2018):** Execute cleanup logic regardless of fulfillment or rejection.57- **Async Iteration (ES2018):** `for await...of` for consuming async iterables.58- **`Array.flat` / `flatMap` (ES2019):** Flatten nested arrays and map-then-flatten in one step.59- **`Object.fromEntries` (ES2019):** Convert key-value pairs back into an object.60- **Optional Catch Binding (ES2019):** `catch { }` without requiring the error parameter.6162### ES2020 & ES2021 (Foundation)63- **Optional Chaining (`?.`):** Safely access deeply nested properties without manual null checks.64- **Nullish Coalescing (`??`):** Provide defaults only for `null`/`undefined`, unlike `||` which also catches `0`, `""`, `false`.65- **`BigInt`:** Arbitrary-precision integer arithmetic via `123n` literal syntax.66- **`Promise.allSettled()`:** Wait for all promises to complete regardless of rejection.67- **`globalThis`:** Universal reference to the global object across all environments.68- **Dynamic `import()`:** Load modules conditionally or lazily at runtime.69- **Logical Assignment (`&&=`, `||=`, `??=`):** Combine logical operators with assignment for concise state updates.70- **`String.prototype.replaceAll()`:** Replace all occurrences without regex.71- **`Promise.any()`:** Resolve with the first fulfilled promise, reject only if all reject.72- **Numeric Separators:** `1_000_000` for readable large numbers.7374### ES2022 & ES2023 (Productivity)75- **Top-level `await`:** Use `await` directly in ESM modules without wrapping in an async function.76- **Error Cause (`{ cause }`):** Chain errors to preserve root cause context.77- **`Array.at()`:** Negative indexing for arrays, e.g., `arr.at(-1)` for the last element.78- **`Object.hasOwn()`:** Safer, prototype-independent property check replacing `hasOwnProperty`.79- **Class Fields:** Public and private (`#field`) instance fields and methods.80- **RegExp Match Indices (`/d` flag):** Get start/end positions of captured groups.81- **Immutable Array Methods:** `toSorted()`, `toReversed()`, `toSpliced()`, `with()` — return new arrays without mutation.82- **`Array.findLast()` / `findLastIndex()`:** Search arrays from the end.8384### ES2024 & ES2025+ (Version-Specific Features)85- **`Promise.withResolvers()`:** Destructure `{ promise, resolve, reject }` for cleaner deferred patterns.86- **`Object.groupBy()` / `Map.groupBy()`:** Group array elements by a classifier function.87- **Set Methods:** `union()`, `intersection()`, `difference()`, `symmetricDifference()`, `isSubsetOf()`, `isSupersetOf()`, `isDisjointFrom()`.88- **Iterator Helpers:** `.map()`, `.filter()`, `.take()`, `.drop()`, `.flatMap()`, `.toArray()` on iterators.89- **`RegExp.escape()`:** Safely escape special characters for use in RegExp construction.90- **Import Attributes:** `import data from './data.json' with { type: 'json' }`.91- **Decorators (Stage 3):** Class and method decorators for cross-cutting concerns.92- **`Promise.try()`:** Safely start a promise chain from a synchronous or asynchronous function.93- **Well-formed Unicode Strings:** `String.prototype.isWellFormed()` and `toWellFormed()`.94- **Temporal API (Stage 3):** A modern replacement for the `Date` object, providing robust date/time arithmetic.95- **Explicit Resource Management (Stage 3):** `using` keyword with `Symbol.dispose` for deterministic cleanup.9697## Coding Standards98- **Variable Declarations:** Always use `const` by default; use `let` only when reassignment is necessary. Never use `var`.99- **Modules:** Use ESM (`import`/`export`) as the default module system. Use `import()` for dynamic/lazy loading.100- **Immutability:** Prefer non-mutating array methods (`toSorted`, `toReversed`, `with`), spread operators, and `structuredClone` for deep copies.101- **Async Safety:** Always wrap `await` in `try`/`catch` or chain `.catch()`. Never leave Promises unhandled. Use `AbortController` for cancellable operations.102103## Deliver104- **Runtime-Optimized Code:** Provide the most appropriate modern syntax code based on the target runtime and ES version.105- **Modernization Insights:** Provide specific refactoring suggestions for upgrading from older JavaScript syntax to new features (e.g., from callbacks to `async`/`await`, from `var` to `const`/`let`).106- **Syntax Explanations:** Clearly explain the design intent and advantages behind the modern JavaScript features used.107108## Validate109- Ensure the provided code complies with the syntax specifications of the target ES version and runtime.110- Validate whether the code follows JavaScript best practices for error handling, null safety, and immutability.111- Confirm the code has good readability and modern conventions (e.g., proper use of destructuring, template literals, ESM).112113## Documentation114### Official References115- [ECMAScript 2025 Language Specification](https://tc39.es/ecma262/)116- [TC39 Proposals (Stage 3+)](https://github.com/tc39/proposals/blob/main/README.md)117- [MDN Web Docs - JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript)118119### Internal References120- [JavaScript Coding Style and Naming Conventions Guide](reference/coding-style.md)121- [JavaScript Anti-Patterns and Best Practices](reference/anti-patterns.md)122- [Modern JavaScript Patterns Guide](reference/patterns.md)