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.
التثبيت
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
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.
compatibility
Supports ES6 (ES2015) through ES2025 and Stage 3+ proposals. Adaptive to modern browser environments and pure JS runtimes.
metadata
{"version":"1.0.0","category":"Core"}
Modern JavaScript (ES6+) Expert Skill
Trigger On
The user asks to write, debug, refactor, or review JavaScript code.
The project directory contains *.js, *.mjs, or JavaScript configuration files (e.g., eslint.config.js, vite.config.js).
HTML files (*.html) or Razor views (*.cshtml) contain inline <script> blocks or reference external .js files via <script src="...">.
The target runtime is a modern browser (Chrome 80+, Firefox 78+, Safari 14+) or a pure JS environment.
Code modernization is needed (e.g., converting var to const/let, callbacks to async/await, legacy scripts to ESM).
Workflow
Perceive (Environment Awareness):
Inspect ESLint / Biome configuration to identify the project's ecmaVersion and coding conventions.
Determine runtime target: browser (check for DOM APIs, bundler config like vite.config.js, webpack.config.js).
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).
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.
Reason (Planning Phase):
Evaluate the modernization level of the current code to determine the refactoring strategy.
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.
In modern environments (modern browsers), actively adopt new features to reduce boilerplate code.
Be aware of browser-specific concerns (DOM manipulation, Web APIs, rendering performance).
Act (Execution Phase):
Write high-quality code using modern syntax to improve readability and maintainability.
Object.groupBy() / Map.groupBy(): Group array elements by a classifier function.
Set Methods:union(), intersection(), difference(), symmetricDifference(), isSubsetOf(), isSupersetOf(), isDisjointFrom().
Iterator Helpers:.map(), .filter(), .take(), .drop(), .flatMap(), .toArray() on iterators.
RegExp.escape(): Safely escape special characters for use in RegExp construction.
Import Attributes:import data from './data.json' with { type: 'json' }.
Decorators (Stage 3): Class and method decorators for cross-cutting concerns.
Promise.try(): Safely start a promise chain from a synchronous or asynchronous function.
Well-formed Unicode Strings:String.prototype.isWellFormed() and toWellFormed().
Temporal API (Stage 3): A modern replacement for the Date object, providing robust date/time arithmetic.
Explicit Resource Management (Stage 3):using keyword with Symbol.dispose for deterministic cleanup.
Coding Standards
Variable Declarations: Always use const by default; use let only when reassignment is necessary. Never use var.
Modules: Use ESM (import/export) as the default module system. Use import() for dynamic/lazy loading.
Immutability: Prefer non-mutating array methods (toSorted, toReversed, with), spread operators, and structuredClone for deep copies.
Async Safety: Always wrap await in try/catch or chain .catch(). Never leave Promises unhandled. Use AbortController for cancellable operations.
Deliver
Runtime-Optimized Code: Provide the most appropriate modern syntax code based on the target runtime and ES version.
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).
Syntax Explanations: Clearly explain the design intent and advantages behind the modern JavaScript features used.
Validate
Ensure the provided code complies with the syntax specifications of the target ES version and runtime.
Validate whether the code follows JavaScript best practices for error handling, null safety, and immutability.
Confirm the code has good readability and modern conventions (e.g., proper use of destructuring, template literals, ESM).