javascript
/javascript
Pomaga pisać czysty, nowoczesny JavaScript z const, let, async/await i destrukturyzacją oraz wyjaśnia domknięcia i pętlę zdarzeń.
- Autor
- DaraBoth ↗
- Repozytorium
- skilljmskill ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 09.11.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 1
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 1
Brak sygnałów. Repozytorium zmienione 09.11.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Pomaga pisać czysty, nowoczesny JavaScript z const, let, async/await i destrukturyzacją oraz wyjaśnia domknięcia i pętlę zdarzeń.
Oryginalny opis (EN)
Standards and patterns for writing clean, modern JavaScript — const/let (no var), async/await over .then chains, template literals, destructuring, and core fundamentals (closures, promises, scope). Use when the user writes or reviews JavaScript, asks to explain JS concepts (hoisting, event loop, this binding, prototypes), or builds browser/Node features in JS. Do not use for TypeScript-specific questions.
Jak działa
- When to Use
- Core Fundamentals
- Clean Function Design
- Error Handling
- Example: Feature Implementation
- Best Practices
- Common Mistakes
Podgląd SKILL.md
---
name: javascript
description: Standards and patterns for writing clean, modern JavaScript — const/let (no var), async/await over .then chains, template literals, destructuring, and core fundamentals (closures, promises, scope). Use when the user writes or reviews JavaScript, asks to explain JS concepts (hoisting, event loop, this binding, prototypes), or builds browser/Node features in JS. Do not use for TypeScript-specific questions.
---
# Skill: JavaScript
> **Purpose**: Write clean, modern JavaScript. Master the fundamentals that matter.
## When to Use
- Writing or reviewing JavaScript code
- Explaining JS concepts (closures, async, promises)
- Building features or fixing JS bugs
---
## Core Fundamentals
### Variables
```javascript
const API_URL = 'https://api.example.com'; // Default — never changes
let retryCount = 0; // Only when reassignment needed
// Never use var — it's function-scoped and causes subtle bugs
```
### Closures
A function that remembers variables from its creation scope.
```javascript
function createCounter(start = 0) {
let count = start;
return {
increment: () => ++count,
decrement: () => --count,
getCount: () => count,
};
}
const counter = createCounter(10);
counter.increment(); // 11
counter.increment(); // 12
counter.getCount(); // 12
```
**When to use**: Private state, factory functions, event handlers with state.
### Promises & Async/Await
```javascript
// ❌ Callback hell
getUser(id, (user) => {
getOrders(user.id, (orders) => {
getDetails(orders[0].id, (details) => { /* nested mess */ });
});
});
// ❌ .then() chains — better but still messy
getUser(id).then(user => getOrders(user.id)).then(orders => getDetails(orders[0].id));
// ✅ async/await — clean and readable
async function getUserOrderDetails(userId) {
const user = await getUser(userId);
const orders = await getOrders(user.id);
const details = await getDetails(orders[0].id);
return details;
}
```
### Destructuring
```javascript
// Objects
const { name, email, role = 'user' } = userData;
// Arrays
const [first, second, ...rest] = items;
// Function parameters
function createUser({ name, email, role = 'user' }) {
return { id: generateId(), name, email, role };
}
```
---
## Clean Function Design
### Rules
1. **One job per function** — if you use "and" to describe it, split it
2. **Max 20 lines** — extract helpers if longer
3. **Descriptive names** — `calculateTotalPrice` not `calc`
4. **Return early** — avoid deep nesting
```javascript
// ❌ Deep nesting
function processOrder(order) {
if (order) {
if (order.items.length > 0) {
if (order.status === 'pending') {
// actual logic buried here
}
}
}
}
// ✅ Early returns
function processOrder(order) {
if (!order) throw new Error('Order is required');
if (order.items.length === 0) throw new Error('Order has no items');
if (order.status !== 'pending') return; // Nothing to process
// Clean, flat logic here
const total = calculateTotal(order.items);
return submitOrder(order.id, total);
}
```
---
## Error Handling
```javascript
// Custom error for domain-specific failures
class ValidationError extends Error {
constructor(field, message) {
super(message);
this.name = 'ValidationError';
this.field = field;
}
}
// Use it
function validateEmail(email) {
if (!email) throw new ValidationError('email', 'Email is required');
if (!email.includes('@')) throw new ValidationError('email', 'Invalid email format');
return true;
}
// Catch specific errors
try {
validateEmail(input);
} catch (error) {
if (error instanceof ValidationError) {
showFieldError(error.field, error.message);
} else {
console.error('Unexpected error:', error);
throw error;
}
}
```
---
## Example: Feature Implementation
**Task**: Build a simple task manager module.
```javascript
// taskManager.js
function createTaskManager() {
const tasks = [];
let nextId = 1;
function addTask(title) {
if (!title || title.trim() === '') {
throw new Error('Task title cannot be empty');
}
const task = {
id: nextId++,
title: title.trim(),
completed: false,
createdAt: new Date().toISOString(),
};
tasks.push(task);
return task;
}
function completeTask(id) {
const task = tasks.find(t => t.id === id);
if (!task) throw new Error(`Task ${id} not found`);
task.completed = true;
return task;
}
function getPending() {
return tasks.filter(t => !t.completed);
}
function getSummary() {
const total = tasks.length;
const done = tasks.filter(t => t.completed).length;
return { total, done, pending: total - done };
}
return { addTask, completeTask, getPending, getSummary };
}
// Usage
const manager = createTaskManager();
manager.addTask('Fix login bug');
manager.addTask('Write unit tests');
manager.completeTask(1);
console.log(manager.getSummary()); // { total: 2, done: 1, pending: 1 }
```
---
## Best Practices
1. **Use `const` by default** — switch to `let` only when needed
2. **Always handle errors** — never empty catch blocks
3. **Use array methods** — `map`, `filter`, `find`, `reduce` for data transforms
4. **Use template literals** — `` `Hello ${name}` `` not `"Hello " + name`
5. **Avoid mutation** — return new objects/arrays when possible
## Common Mistakes
| Mistake | Fix |
|---------|-----|
| Using `==` instead of `===` | Always use strict equality |
| Forgetting `await` | Missing await = working with Promise object, not value |
| Mutating function arguments | Clone first: `const copy = [...arr]` |
| Not handling Promise rejections | Always `.catch()` or try/catch with await |
| Using `this` in arrow functions | Arrow functions inherit `this` — use regular functions in classes |
Wersje
| Repozytorium | Wynik | Licencja |
|---|---|---|
| Ta strona · DaraBoth/skilljmskill | 100 | MIT |
| workbench-soft/agent-skills | 100 | MIT |
| claude-dev-suite/claude-dev-suite | 100 | MIT |
| alexander-danilenko/cortex-claude-code-plugins | 100 | MIT |
| G1Joshi/Agent-Skills | 100 | MIT |
| aj-geddes/unicorn-team | 100 | MIT |
| autocss-com/ai | 90 | MIT |
| clawic/skills | 90 | MIT |
| dkbnull/hello-skill | 86 | MIT |
Migawka bazy z 13.11.2026 · wersja paczki acb375d790a8 (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 0 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100js-modern
Pisze nowoczesny JavaScript i TypeScript (ES6+, async/await, moduły, optional chaining, typy) dla motywów, aplikacji i headless storefrontów BigCommerce. - 100js-modern
Pisze nowoczesny JavaScript i TypeScript (ES6+, async/await, moduły, optional chaining, typy) dla motywów, aplikacji, Functions i storefrontów Hydrogen w Shopify. - 100modern-javascript-patterns
Uczy nowoczesnych wzorców ES6+ (async/await, destrukturyzacja, moduły, generatory, programowanie funkcyjne) przy refaktoryzacji starego kodu i optymalizacji aplikacji JavaScript. - 91modern-javascript-patterns
Uczy funkcji ES6+ w JavaScript, takich jak async/await, destrukturyzacja, moduły, promisy i generatory, pod kątem czystego kodu, refaktoryzacji legacy i optymalizacji aplikacji. - 100javascript-pro
Tworzy i debuguje nowoczesny kod JavaScript z ES6+, wzorcami asynchronicznymi i API Node.js, przy zachowaniu w czasie wykonania, promises i zgodności przeglądarki z Node. - 91modern-javascript-patterns
Przedstawia nowoczesne wzorce JavaScript: async/await, destrukturyzację, spread, funkcje strzałkowe, promisy, moduły, iteratory, generatory i programowanie funkcyjne, przydatne przy refaktoryzacji starszego kodu.