Creators to follow

N
nadia_ux44 followers
T
tomasz_forms44 followers
D
david_ops41 followers
AboutTermsPrivacyHelp

© 2026 teliprompt

MA
marcus_react
8 months ago•
Coding

Legacy JavaScript to modern ES2023 refactor

GPT-4.1
code output
#javascript
#refactor
#es2023
#modernization
#nodejs
Views
9.0K
Copies
1.5K
Likes
1.3K
Comments
0
Copy rate
17.0%

Prompt

You are a senior JavaScript engineer. Refactor the legacy JavaScript snippet below into idiomatic modern ES2023.

Legacy source:
[legacy_source]

Target runtime: [target_runtime]

Apply every one of these transformations where applicable:
- Replace every `var` with `const` (or `let` only if reassigned)
- Replace `function` expressions with arrow functions when `this` is not needed
- Replace callback-based async (`fn(err, data) => ...`) with `async`/`await` over Promises
- Replace `.then().catch()` chains with `try`/`catch` inside `async` functions
- Use optional chaining (`?.`) and nullish coalescing (`??`) instead of manual truthy checks
- Use object/array destructuring for access patterns
- Use template literals instead of string concatenation
- Use `for...of` over manual index loops; use `Array.prototype.at(-1)` for last element
- Use `Object.groupBy`, `Array.prototype.findLast`, `Array.prototype.toSorted` where relevant
- Use top-level `await` if target runtime supports ES modules
- Replace `JSON.parse(JSON.stringify(x))` with `structuredClone(x)`
- Add JSDoc types on every exported function

Output format:
- Return only the final .js file
- No prose, no markdown fences
- End with a short `// Summary of changes` comment block listing every transformation applied

Customise this prompt

Fill in 2 variables to personalise this prompt

Preview
You are a senior JavaScript engineer. Refactor the legacy JavaScript snippet below into idiomatic modern ES2023. Legacy source: [legacy_source] Target runtime: [target_runtime] Apply every one of these transformations where applicable: - Replace every `var` with `const` (or `let` only if reassigned) - Replace `function` expressions with arrow functions when `this` is not needed - Replace callback-based async (`fn(err, data) => ...`) with `async`/`await` over Promises - Replace `.then().catch()` chains with `try`/`catch` inside `async` functions - Use optional chaining (`?.`) and nullish coalescing (`??`) instead of manual truthy checks - Use object/array destructuring for access patterns - Use template literals instead of string concatenation - Use `for...of` over manual index loops; use `Array.prototype.at(-1)` for last element - Use `Object.groupBy`, `Array.prototype.findLast`, `Array.prototype.toSorted` where relevant - Use top-level `await` if target runtime supports ES modules - Replace `JSON.parse(JSON.stringify(x))` with `structuredClone(x)` - Add JSDoc types on every exported function Output format: - Return only the final .js file - No prose, no markdown fences - End with a short `// Summary of changes` comment block listing every transformation applied

Example output

Related prompts

Async iterators and generators in modern JavaScript: a working guideby @olivia_test
Coding
TypeScript type narrowing cheat sheet with runnable examplesby @marcus_react
Coding
CLI tool builder with argument parsing and colored outputby @nikolai_rust
Coding
Convert JavaScript to strict TypeScript with full type safetyby @marcus_react
Coding