unrust

JavaScript skill practice

How do you approach this?

Reviewing AI-Generated JavaScript Code

Published · Updated

Published by Unrust. Scoring and editorial method

Quick answer

Review AI-generated JavaScript by checking what the code will do at runtime, not only whether it parses or resembles a familiar snippet. Inspect data validation, truthiness, mutable references, promise rejection paths, and the installed API surface. Generated JavaScript can look concise while relying on a missing method, swallowing an error, or mutating an object that another caller still owns.

Original example

Question an unvalidated request body before using it

const body = JSON.parse(request.body);
const accountId = body.accountId;
await loadAccount(accountId);

This original JavaScript example is deliberately small so the review questions remain visible: is request.body always a string, what happens when parsing fails, what shape does accountId require, and who handles a rejected load? The correct implementation depends on the application's request and error contract, not on a generic generated pattern.

Review runtime assumptions with concrete values

Types may be absent or broad in JavaScript, so test the values that matter: missing fields, false and zero, malformed input, and rejected promises. Check each boundary against the caller's contract instead of accepting a generic fallback that silently changes what downstream code observes.

Inspect async failure and cleanup paths

A generated happy-path await can conceal an unhandled rejection, duplicate request, stale state update, or missing cleanup action. Trace what happens when the external operation fails, resolves late, or is cancelled, then add focused evidence proportional to the consequence of getting that path wrong.

Check a concrete outcome

Use the original example with this input. These are local teaching fixtures, checked against the displayed snippet; they do not call external services.

The local stub records that unvalidated input reaches loadAccount. No real account or network is used. Parsing JSON is not validation or authorization; enforce the application's real policy at the trusted boundary.

Input and local fixtures
const request = {body: '{"accountId":"outside-scope"}'};
const loaded = [];
const loadAccount = async (id) => { loaded.push(id); };
Checked observation
Expression after the exampleObserved result
loaded["outside-scope"]

Checklist

  • What runtime values can cross this JavaScript boundary?
  • Who owns rejected promises, cancellation, and cleanup?
  • Does the installed package actually expose the imported API and signature?

Practice loop

  1. 01Run an AI-suggested JavaScript change with missing, falsy, and malformed inputs when they are relevant.
  2. 02Verify that every promise rejection and cleanup path has an intentional owner.
  3. 03Confirm imports and method signatures against the installed package version before merging.

Limits of this page

Runtime checks should be scaled to the risk of the change and cannot cover every browser, deployment, or dependency interaction. A single review exercise cannot establish that AI or any tool caused a result, nor can it distinguish unfamiliar project context from a durable skill issue.

Source context

Published by Unrust as practical teaching material using public language documentation and original examples. See the scoring and editorial method for scope, checking and limitations.

Check your own starting point

One diagnostic session is a snapshot, not causal proof of why a result occurred. It can help you choose a focused next practice step without making a broader claim about your ability.

Take the free diagnostic

Take the read in JavaScript →Same six skills, side by side on your dashboard.