Skills modern-javascript-patterns
📦

modern-javascript-patterns

Safe

Apply Modern JavaScript Patterns

Legacy JavaScript codebases are difficult to maintain and optimize. This skill provides comprehensive guidance on ES6+ features including arrow functions, destructuring, async/await, promises, functional programming patterns, and modern class features to write clean, efficient, and maintainable JavaScript code.

Supports: Claude Codex Code(CC)
📊 69 Adequate
1

Download the skill ZIP

2

Upload in Claude

Go to Settings → Capabilities → Skills → Upload skill

3

Toggle on and start using

Test it

Using "modern-javascript-patterns". How do I destructure nested objects in JavaScript?

Expected outcome:

Nested object destructuring allows you to extract values from deeply nested objects:

```javascript
const user = {
id: 1,
name: 'Alice',
address: {
city: 'Boston',
country: 'USA'
}
};

// Nested destructuring
const {
name,
address: { city, country }
} = user;

console.log(city); // 'Boston'
console.log(country); // 'USA'

// With default values
const {
address: {
city = 'Unknown',
zipCode = '00000'
} = {}
} = user;
```

Using "modern-javascript-patterns". What's the difference between Promise.all and Promise.allSettled?

Expected outcome:

Promise.all fails fast - if any promise rejects, the entire operation fails. Promise.allSettled waits for all promises to settle regardless of outcome:

```javascript
// Promise.all - fails on first rejection
const users = await Promise.all([
fetchUser(1),
fetchUser(2)
]); // Throws if either fails

// Promise.allSettled - waits for all
const results = await Promise.allSettled([
fetchUser(1),
fetchUser(2)
]);

results.forEach(result => {
if (result.status === 'fulfilled') {
console.log('Success:', result.value);
} else {
console.log('Failed:', result.reason);
}
});
```

Security Audit

Safe
v5 • 1/21/2026

This is a documentation skill containing educational content about JavaScript ES6+ patterns. All static analysis findings are false positives. The 'weak cryptographic algorithm' flags are triggered by JavaScript template literals and class private field syntax (#). The 'shell backtick execution' flags are false positives from JavaScript template literals in code examples. The 'dynamic import()' detections are legitimate ES6 module examples being documented. No malicious code patterns exist.

2
Files scanned
1,897
Lines analyzed
0
findings
5
Total audits
No security issues found
Audited by: claude View Audit History →

Quality Score

38
Architecture
100
Maintainability
87
Content
21
Community
100
Security
83
Spec Compliance

What You Can Build

Refactor Legacy JavaScript Codebases

Migrate callback-based code to Promises and async/await patterns. Replace traditional functions with arrow functions to fix 'this' binding issues. Apply destructuring and spread operators to simplify data manipulation.

Learn Functional Programming in JavaScript

Understand how to use map, filter, and reduce for data transformation. Learn to create pure functions that avoid side effects. Apply function composition and piping for readable data processing pipelines.

Write Maintainable JavaScript Code

Apply modern JavaScript patterns for cleaner, more expressive code. Use proper module organization and ES6 class features. Implement performance optimizations like debouncing, throttling, and lazy evaluation.

Try These Prompts

Basic ES6+ Question
How do I use [feature] in modern JavaScript? Can you show me examples of [use case]?
Refactoring Legacy Code
I have this legacy JavaScript code: [code snippet]. How can I refactor it to use modern ES6+ patterns? What specific features should I apply?
Async Pattern Implementation
I need to implement [specific async task]. Should I use Promises, async/await, or a combination? Show me the best practice pattern for [scenario] with proper error handling.
Functional Programming Challenge
I have an array of objects: [data structure]. How can I use functional programming to [transform/group/filter/aggregate] this data? Show me step-by-step how to compose functions for this task.

Best Practices

  • Use const by default and only use let when reassignment is truly needed. This prevents accidental mutations and makes code intent clearer.
  • Prefer arrow functions for callbacks and methods that need lexical 'this' binding. Use traditional functions only when you need dynamic 'this'.
  • Apply destructuring and spread operators for cleaner data manipulation. Avoid direct property access and mutation when possible.

Avoid

  • Avoid wrapping already async functions in new Promises. If a function already returns a Promise, use it directly with await.
  • Do not mutate input data in functions. Always return new objects or arrays using spread operators to maintain immutability.
  • Avoid callback pyramids and excessive Promise chaining. Use async/await for better readability and error handling.

Frequently Asked Questions

What is the difference between arrow functions and traditional functions in JavaScript?
Arrow functions have lexical 'this' binding (inherit from surrounding scope) and cannot be used as constructors. Traditional functions have dynamic 'this' binding and can be called with 'new'. Use arrow functions for callbacks and methods where 'this' should not change.
When should I use async/await vs Promises directly?
Use async/await for most cases as it produces more readable code similar to synchronous code. Use Promises directly when composing multiple async operations with Promise.all, Promise.race, or Promise.allSettled.
How do I handle errors with async/await?
Wrap await calls in try/catch blocks. For multiple independent async operations, consider using Promise.allSettled to handle failures gracefully without stopping the entire operation.
What are the benefits of functional programming in JavaScript?
Functional programming makes code more predictable and easier to test. Pure functions always produce the same output for the same input and have no side effects. Array methods like map, filter, and reduce create chainable transformations that are readable and maintainable.
When should I use destructuring vs direct property access?
Use destructuring when extracting multiple properties from an object or array. It makes code cleaner and declares all variables at once. Use direct access for single property access in simple cases.
What are the performance implications of modern JavaScript features?
Modern JavaScript features are optimized by modern engines. Some patterns like spread operators on large arrays can create performance overhead. Use debouncing and throttling for event handlers. For intensive operations, consider generators for lazy evaluation.