Join WhatsApp
Sample output Ā· AI-generated

1. Summary
This function delays running another function until the user stops triggering it for a set time. It is often used so a search box does not send a request on every key press.

2. Line by line
```js
function debounce(fn, delay) {
let timer;
return function (...args) {
clearTimeout(timer);
timer = setTimeout(() => fn.apply(this, args), delay);
};
}
```
function debounce(fn, delay): takes the function to delay and the wait time in milliseconds.
let timer: stores the ID of the waiting timer. It lives on between calls.
return function (...args): returns a new function that collects whatever arguments it gets.
clearTimeout(timer): cancels the previous wait, if any.
setTimeout(...): starts a new wait; when it ends, fn runs with the latest arguments.

3. Key concepts
Closure: the inner function remembers timer. Rest parameters: ...args gathers all arguments.

4. Example
const search = debounce(q => fetchResults(q), 300); search("sh"); search("shoes"); runs fetchResults("shoes") once, 300 ms later.

5. Watch out
Turning the returned function into an arrow function would break code that relies on this, because arrow functions do not get their own this.

Text prompt Ā· ChatGPT Ā· Claude Ā· Gemini

Explain code prompt for beginners, line by line

Paste any snippet and get a plain-English summary, a line-by-line walkthrough and the concepts you need to understand it.

You are a patient programming teacher. Explain this [language] code to me.

My level: [beginner, intermediate, experienced in another language]
Where the code comes from: [project, tutorial, open source library]
Code:
```
[paste code]
```

Explain in this order:
1. Summary: what the code does, in 2 sentences, without jargon.
2. Line by line: go through each line or small block and say what it does and why.
3. Key concepts: name each concept used (for example closures, recursion, async), with a one-line definition.
4. Example: show how this code is called and what it returns or prints.
5. One thing that could go wrong when using it.

Keep the explanation at my level. Do not change the code unless I ask.
Type
Text
Fill in
4 blanks
Copies
Be the first

Updated Ā· By

Tip: After reading the explanation, close it and try to explain the code out loud; any part you cannot explain is the part to ask about.

1. CopyTap "Copy prompt" above.
2. Fill the blanksReplace each [bracket] with your own details.
3. Paste + refinePaste it into the chat, then ask for changes.

Why this prompt works

This explain code prompt sets your level and a fixed order: summary first, details second. Starting with a plain summary gives you the big picture, so the line-by-line part makes sense instead of feeling like a list of facts.

Naming the concepts used, such as closures, gives you the exact words to search for later. The example call shows the code in action, and "one thing that could go wrong" turns a reading exercise into practical knowledge you can use in your own code.

How to use this prompt

  1. Tap "Copy prompt".
  2. Replace every part in [square brackets] with your own details.
  3. Paste it into ChatGPT or Claude and send.
  4. Ask a follow-up like "make it shorter" or "give me 3 more options" to fine-tune it.

Variations to try

Explain a whole file or module

ChatGPT Claude Gemini
Explain this [language] file to a developer joining the project. Give the purpose of the file, the main functions or classes with one line each, how data flows through it, and which other files it probably depends on. File: [paste file].
Type
Text
Fill in
2 blanks
Copies
Be the first

Explain with a diagram in text

ChatGPT Claude Gemini
Explain how this code works and draw a simple text flowchart of the steps using arrows made of dashes and greater-than signs. Code: [paste code]. My level: [level].
Type
Text
Fill in
2 blanks
Copies
Be the first

Turn it into a quiz

ChatGPT Claude Gemini
After explaining this code, give me 5 short quiz questions to check I understood it, with answers hidden at the end. Code: [paste code].
Type
Text
Fill in
1 blank
Copies
Be the first

Make it your own

  • Ask for comparisons with a language you know: "Explain it using Python equivalents".
  • Add "Explain in simple English for a non-native speaker" if that helps.
  • Ask it to add comments to the code instead of a separate explanation.

Common problems and fixes

  • The explanation is too advanced. State your level clearly and ask for an everyday analogy for each concept.
  • The AI changes the code while explaining. Keep "do not change the code unless I ask" in the prompt.

FAQ

Can I use this to understand code for my coursework?

Yes, to learn how it works. Check your school's rules on AI use before submitting any work.

Does it work with any programming language?

Yes. Name the language in the prompt so the AI uses the right terms.

More Coding prompts

See all
ChatGPT Claude Text prompt

Debug code prompt that finds the root cause before fixing

Paste your code and the error message to get the real cause explained first, then a small fix and a test for it.

4 prompts
ChatGPT Claude Text prompt

Unit test prompt for edge cases in pytest or Jest

Get a list of test cases for a function, then ready-to-run tests for normal input, edge cases and errors in your framework.

3 prompts
ChatGPT Claude Text prompt

Refactor code prompt for cleaner, more readable functions

Clean up a messy function while keeping its behaviour the same, with a short list of every change and the reason for it.

4 prompts
ChatGPT Claude Text prompt

SQL query prompt: describe your tables, get the query

Describe your tables and the question you want answered, and get a correct query for your database with a short explanation.

4 prompts
ChatGPT Claude Text prompt

Regex prompt that writes and explains a pattern with tests

Describe what you want to match and get a working pattern for your language, explained piece by piece, with examples that should and should not match.

4 prompts
ChatGPT Claude Text prompt

Code review prompt for bugs, security and readability

A structured review of a pull request or snippet, with issues sorted by severity, each tied to a line and a suggested fix.

3 prompts
ChatGPT Claude Text prompt

API design prompt for clean REST endpoints and errors

Plan a REST API for a feature: endpoints, example requests and responses, status codes, error format and the decisions behind them.

4 prompts
ChatGPT Claude Text prompt

Vibe coding prompt: write an app spec before you build

Turn an app idea into a clear spec with features, screens, data and build steps that an AI coding assistant can follow one step at a time.

4 prompts