JavaScript Implementation and Debugging
Write, debug, and refactor browser and Node.js JavaScript with bounded async flows, correct modules, and targeted regression checks.
Before & after
Same prompt, same agent — the only difference is the skill.
Async functions returning undefined usually means something isn't being awaited or returned properly. Common causes: - Forgetting to return the value from the async function - Not awaiting a Promise inside the function - A race condition where the value isn't ready yet - An error being swallowed by a try/catch I'd check whether every Promise is awaited and whether the function actually returns the result. Adding some logging can help trace where the value gets lost. Can you share the function?
Undefined from an async function is almost always one of three bugs.
Diagnose in this order:
1. MISSING RETURN INSIDE .then / callback
const get = async () => { fetchData().then(d => d.value) }
The arrow returns nothing; the .then result is discarded. Fix: await
and return, or return the chain.
2. FORGOTTEN await ON A NESTED CALL
const x = getUser() // returns a Promise, not a user
x.name is undefined because x is a pending Promise. await it.
3. forEach WITH async — the silent one
arr.forEach(async i => { results.push(await f(i)) })
forEach ignores the returned Promises; the function moves on before
any push happens. This is the single most common cause.
Fix: for...of with await, or Promise.all(arr.map(f)).
MODERN FIX FOR #3
const results = await Promise.all(arr.map(f))
Runs them concurrently AND waits for all — forEach does neither.
THE DEBUGGING MOVE
Log typeof at the return: a "object" that's actually a Promise (has a
.then) tells you it's a missing await, not a missing value. A genuine
undefined tells you it's a missing return.
Paste the function and I'll point at the exact line.About this skill
“My promises finish in the wrong order,” “this import works locally but fails in production,” and “the browser freezes” need different fixes. This skill traces the actual JavaScript behavior, makes a focused correction, and gives you checks that expose the original failure.
What it does
- Writes vanilla browser and Node.js utilities while preserving your existing interfaces and module conventions.
- Replaces uncontrolled async work with bounded concurrency, ordered results, and explicit failure and cancellation behavior.
- Diagnoses ESM and CommonJS problems using file extensions, package settings, execution commands, and export boundaries.
- Finds JavaScript correctness bugs involving coercion, missing values, mutation, object identity, and stale async results.
- Separates network delays, CPU work, and rendering costs before choosing caching, yielding, streams, or workers.
- Reviews pasted code with concrete failure paths, focused fixes, and regression checks.
What you get
Runnable JavaScript or a focused patch, an explanation of the behavior it fixes, and targeted validation steps. Reviews prioritize reproducible defects and identify assumptions about runtime support.
Best for
Developers building or maintaining framework-free browser code, Node.js utilities, shared JavaScript packages, and async data flows.
SKILL.md preview
---
name: javascript-implementation-and-debugging
description: Writes, debugs, and refactors browser and Node.js JavaScript by tracing language semantics, async ownership, module resolution, and runtime costs, then producing focused code and regression checks. Use when the user says "fix this JavaScript", "my promises finish out of order", "my fetch loop freezes the browser", "this import works locally but fails in production", "refactor this callback code", "review this .mjs file", or "make this Node.js utility faster".
---
# JavaScript Implementation and Debugging
… (sign up to view the full skill)More development skills
View all Development skills →SQL Query Optimization and Schema Review
Get SQL rewrites, evidence-based index recommendations, schema reviews, and dialect migrations with validation steps.
C# API and Blazor Implementation
Build and fix C# APIs and Blazor components with safe EF Core queries, cancellation, and focused tests.
Rust Code Implementation and Debugging
Get Rust code and targeted fixes for ownership, lifetimes, traits, Tokio concurrency, errors, and unsafe boundaries.
Type-Safe PHP Applications and APIs
Build and repair typed PHP applications with Laravel or Symfony, safe database changes, and targeted tests.