JavaScript, starting from the code that misbehaves
Language questions are easier to answer against a snippet: equality, async order, mutation, or a closure that captured the wrong value.
Be specific about the runtime
Say whether the code runs in a browser, Node, or both. APIs and module rules differ.
Include the unexpected value if you have it. “It logs the wrong thing” is less useful than the actual log line.
Example prompt
Explain why this loop logs 3 three times, and rewrite it so each callback sees its own index.
- Paste the loop, not a description of it.
- Ask for the explanation and the rewrite separately if you want to compare them.
Questions
Can it generate tests too?
Yes. Ask for unit tests after the behavior is clear, and run them yourself.