modern-javascript-patterns

Refactor JavaScript code using ES6+ syntax, async patterns, and functional programming techniques.

Updated Apr 23, 2026
One-click install
npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill modern-javascript-patterns-sanketadlak
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: modern-javascript-patterns
Source: https://github.com/SanketAdlak/PDMProjectDesign/tree/main/.agents/skills/modern-javascript-patterns
Command: npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill modern-javascript-patterns-sanketadlak

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Legacy JavaScript codebases often rely on outdated patterns like callback pyramids, var declarations, and manual string concatenation, making code hard to read, test, and maintain. This Skill provides concrete guidance for modernizing JavaScript with ES6+ features and functional programming patterns. ## Core Features & Use Cases - ES6+ Syntax Modernization: Apply arrow functions, destructuring, spread/rest operators, template literals, and enhanced object literals to replace verbose legacy code. - Asynchronous Patterns: Convert callback chains to Promises and async/await, use Promise combinators (all, allSettled, race, any), and implement retry and timeout wrappers. - Functional Programming: Use map/filter/reduce pipelines, currying, memoization, function composition, and immutable data operations. - Use Case: When refactoring a legacy Express route handler with nested callbacks, use this Skill to rewrite it with async/await, destructure request parameters, and apply immutable state updates. ## Quick Start Refactor this JavaScript file to use modern ES6+ syntax with async/await and destructuring.

Frequently Asked Questions about modern-javascript-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I convert callback functions to async/await in JavaScript?

Wrap callback-based operations in Promises, then use async functions with await to consume them. Handle errors with try/catch blocks instead of error-first callbacks, and use Promise.all for parallel execution of independent operations.

What is the difference between Promise.all and Promise.allSettled?

Promise.all rejects immediately when any promise fails, while Promise.allSettled waits for all promises to complete and returns each result with a fulfilled or rejected status. Use allSettled when you need every outcome regardless of individual failures.

When should I use nullish coalescing instead of logical OR?

Use the nullish coalescing operator (??) when 0, empty string, or false are valid values, since it only defaults on null or undefined. Logical OR (||) treats all falsy values as missing, which causes bugs with numeric zero or empty strings.

Does optional chaining work with function calls and arrays?

Yes, optional chaining supports method calls with obj.method?.() and array access with arr?.[0]. It short-circuits to undefined when any part of the chain is null or undefined, preventing 'Cannot read property of undefined' errors.

Why does 'this' become undefined inside setTimeout callbacks?

Traditional functions create their own 'this' binding, so callbacks lose the enclosing context. Arrow functions capture 'this' lexically from the surrounding scope, making them the standard fix for callbacks in class methods and timers.

What are the limitations of JSON.parse(JSON.stringify()) for deep cloning?

This approach loses functions, undefined values, Dates, Maps, Sets, and circular references throw errors. Use the built-in structuredClone() function instead, which handles most built-in types and circular structures correctly.