Trending today

1

Create a deep RPG character backstory with motivations, flaws, and arc potential

11.8K views
2

Anomaly detection with rolling z-score windows in SQL

11.8K views
3

30-day social media content calendar with post templates

11.6K views
4

Structured logging with correlation IDs across microservices

11.4K views
5

Legacy JavaScript to modern ES2023 refactor

10.9K views

Creators to follow

N
nadia_ux45 followers
D
david_ops45 followers
P
priya_design44 followers
AboutTermsPrivacyHelp

© 2026 teliprompt

MA
marcus_react
2 days ago•
Coding

Legacy JavaScript to modern ES2023 refactor

GPT-4.1
code output
#javascript
#refactor
#es2023
#modernization
#nodejs
Views
10.9K
Copies
2.6K
Likes
1.3K
Comments
0
Copy rate
24.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

Task automation script with retry logic and notificationsby @jess_python
Coding
Python dataclass to Pydantic v2 model converterby @jess_python
Coding
Custom React hook with TypeScript generics and full test suiteby @marcus_react
Coding
Regex builder with visual explanation and test casesby @mei_swift
Coding