High Javascript

Use async/await over callbacks and .then()

Rule Description

Prefer async/await for asynchronous code:
- More readable than callbacks or .then() chains
- Easier error handling with try/catch
- Works naturally with loops and conditionals

```typescript
// Good
async function fetchUserData(id: string): Promise {
try {
const response = await fetch(`/api/users/${id}`);
if (!response.ok) throw new Error('Failed to fetch');
return await response.json();
} catch (error) {
logger.error('Failed to fetch user', { id, error });
throw error;
}
}

// Avoid
function fetchUserData(id) {
return fetch(`/api/users/${id}`)
.then(res => res.json())
.catch(err => console.log(err));
}
```

Included in Rulesets

React Standards
28 rules • 1 standard
View
Vue Best Practices
28 rules • 1 standard
View
Angular Guidelines
28 rules • 1 standard
View
Next.js Patterns
28 rules • 1 standard
View
Express Standards
31 rules • 1 standard
View
JavaScript Guide
28 rules • 2 standards
View
TypeScript Guide
28 rules • 4 standards
View
Code Review Standards
58 rules • 0 standards
View

Add This Rule

Sign in to add this rule to your workspace

Sign in with GitHub

Details

Severity
High
Category
Javascript
Used in
8 rulesets