T0 Learning to learn · Lesson 5
Searching well, judging answers, and asking for help
Search operators that find exactly what you need, how to rank sources and judge an answer, how to read a project's issues, how to write a question people want to answer, and how to understand an answer's code before you use it.
- narrow a search with quotes, minus, site: and the tool's version
- rank sources and judge an answer by six signs and your own test
- read a GitHub issue: its state, labels, workaround and fixing version
- write a question with a clear title, the four things and a runnable smallest example
- take an answer's code apart from the inside out before using it
The back cover
Almost every problem a programmer meets has been met before, by somebody, somewhere. The answer usually exists. The skill lies in finding it, judging whether it can be trusted, and using it with understanding, instead of pasting it in blind.
These pages start with a few short instructions that make a search engine narrow its results like a good librarian. Then come the signs of a reliable source and of a good answer, and a tour of a project's public list of bugs, where the people who wrote a tool answer questions about it.
The last two parts are about people. A question written well gets answered within the hour, and the code in an answer should be taken apart and understood before it goes into a program.
Before you start
The story: The notice board
You have been stuck for an hour. A clock in the shop prints its chimes twice, and nothing in the manual explains why.
The Lantern Society's notice board, in the room above the shop, is covered in old questions and answers, pinned in layers. Some are years old. Some contradict each other. One, in big confident letters, says: "Clocks print twice? Take out the second spring." Corin is already reaching for a screwdriver.
Ilse taps the board. "Anyone can pin an answer," she says. "Your job is to know which one to trust. And if none fits, to ask a question someone can answer."
Lesson 2 showed how to turn an error message into a search. This lesson goes further. It shows how to make a search engine find exactly what you need, and how to tell a good answer from a bad one. Then it reads a project's bug list, and shows how to ask people for help so that they want to answer. It builds on these ideas.
| What you already know | A tiny example | Where it comes back |
|---|---|---|
| Search the fixed words of a message. | javascript "Cannot read properties of undefined (reading" | Search operators make this even sharper. |
| Drop your own names. | shopName and booking.js are yours alone. | The same rule makes a question readable by others. |
| MDN first, then Stack Overflow. | MDN explains the message; Stack Overflow shows real cases. | This lesson ranks every kind of source. |
| Check the date and version of an answer. | An answer from 2015 may use var. | Judging an answer needs a few more checks. |
| The smallest example. | Cut a crash down to the two lines that still show it. | It is the heart of a good question. |
| Never paste a secret. | Replace a key with the word SECRET. | Questions and logs are public. |
| Test before you trust. | Turn each claim into a one-line test. | Every answer you find gets tested the same way. |
| Versions: MAJOR.MINOR.PATCH. | An answer for version 3 may not fit version 4. | Bug reports often end with "fixed in 4.2.1". |
| Asking at a help desk. | "Is train 12128 late?" gets an answer; "my train is late" does not. | A good question is exact, short and complete. |
By the end of this lesson you will be able to:
- use search operators (quotes, minus, site:) to narrow a search to what you need;
- rank sources, and judge an answer by six signs before you use it;
- read a GitHub issue: its state, its labels, its workaround and the version that fixes it;
- write a question with a clear title, the four things a helper needs and a runnable smallest example;
- test an answer's code in a tiny program before putting it into your own.
In one line
This lesson sharpens the searching and asking of lesson 2, using the smallest example of lesson 3 and the testing habit of lesson 4.
Making a search engine find exactly what you need
At a glance
A search operator is a short instruction typed into a search box. It tells the search engine how to use the words, and not only which words to look for. Quotes around a message keep its words together and in order. A minus sign in front of a word leaves out every page that contains it. The word site: followed by an address searches one website only.
The strongest narrowing of all is not an operator: the name of the tool and its version. These instructions work in Google, Bing and DuckDuckGo, though each engine adds and drops operators over the years, and its help page lists the ones it supports.
Take a guess: A search for an error message brings up essays about arguments: what one change would fix that?
Ask a librarian for "a book about trains" and you get a shelf. Ask for "the Indian Railways timetable for 2026, not the old one, from the government's own office" and you get one book. Search engines listen the same way, and they understand a few short instructions that do the librarian's narrowing for you.
A short instruction typed into a search box, such as quotes or a minus sign, that tells the search engine how to use your words rather than only which words to look for.
| Operator | Example | What it does |
|---|---|---|
| Quotes | "missing ) after argument list" | finds pages with those words together, in that order |
| Minus | toFixed rounding -python | leaves out pages that contain the word after the minus |
| site: | padStart site:developer.mozilla.org | searches only one website |
| The tool and its version | node 22 fetch timeout | not an operator, but the strongest narrowing word of all |
These work in Google, Bing and DuckDuckGo. Search engines add and drop operators over the years; if one seems to stop working, each engine's help page lists the ones it supports today.
Why each one helps
Quotes stop the engine from treating your words as a loose bag. Without them, a search for missing ) after argument list finds pages about missing people and argument essays. With them, it finds the error.
Minus removes a whole family of wrong results. Many words exist in several languages: toFixed is JavaScript, but rounding questions come from Python, Java and Excel too. A minus before the word python takes those pages out.
site: sends you straight to a source you trust. site:developer.mozilla.org for MDN, site:stackoverflow.com for Stack Overflow, site:github.com for projects and their bug lists, site:nodejs.org for Node's own docs.
Worked example 1
You want MDN's page on padEnd, and the search padEnd gives you blogs and videos first. Make a search that goes straight to MDN.
What we have: the method's name and MDN's address, developer.mozilla.org
What we need: a search whose first result is MDN's page
The plan: add site: with MDN's address
- Start with the method name: padEnd.
- Add the operator for one website: site:developer.mozilla.org.
- No space after the colon: site: and the address are one piece.
padEnd site:developer.mozilla.org.
Check: every result is now on MDN, and the first is the page called String.prototype.padEnd().
Another way: many people type mdn padEnd instead; it usually works too, because MDN pages contain the word MDN.
Worked example 2
A search for javascript round to 2 decimal places returns many Python and Excel pages. Narrow it.
What we have: a search that mixes languages
What we need: results only about JavaScript
The plan: remove the other languages with minus signs, and quote the exact phrase
- Quote the phrase you mean: "2 decimal places".
- Keep javascript, and remove the languages that crowd in: -python -excel.
javascript "2 decimal places" -python -excel.
Check: the remaining results are about JavaScript, and many mention toFixed, the method lesson 4 read.
A path that fails: adding more and more words, such as javascript round number two decimal places correctly. Each extra word matches more pages of the wrong kind; removing the wrong kind with minus works better.
Worked example 3
An error appears only since you updated Vite, a tool that builds websites, from version 6 to version 7. Make a search that finds people with the same problem since that version.
What we have: the error's fixed words and the version number
What we need: results about version 7, not version 6
The plan: quote the error's fixed words and add the tool's name with its major version
- Quote the fixed words of the error message, as lesson 2 taught.
- Add vite 7. The version is the strongest narrowing word here: the problem began with it.
- Add site:github.com, where the tool's own bug list lives.
vite 7 "fixed words of the error" site:github.com, with the real fixed words in place of the quoted text.
Check: results now come from the project's own issues about version 7, where a fix or workaround is most likely.
When you are stuck: a search that finds the wrong things
Look at what the wrong results have in common: another language, another tool, an old version. Remove it with a minus.
Quote the words that must stay together.
Send the search to one trusted site with site:.
Add the tool's name and major version.
Your turn
Make a search for MDN's page on the trim method of strings.Tap to reveal
- Use the method name and the operator for one site.
trim site:developer.mozilla.org (or mdn string trim).
What does the minus sign do in includes case sensitive -java?Tap to reveal
- It acts on the word right after it.
It leaves out pages that contain java.
Why do quotes help when you search for an error message?Tap to reveal
- Without them, the engine treats the words as a loose bag.
They make the engine find the words together and in order, as the error has them.
Did you know?
The first search engine came before the web
Before the World Wide Web existed, the internet already held files on many computers, and finding one was hard. Alan Emtage, a student at McGill University in Montreal, built a tool that kept an index of those files so that people could search it. He called it Archie, and it is widely considered the first internet search engine. Emtage was born in Bridgetown, Barbados, and joined the Internet Hall of Fame in 2017.
Why it fits here: Every search box since, including the one these operators are typed into, does the job Archie began: finding the one thing wanted in a huge collection.
Sources: Wikipedia: Archie (search engine); Wikipedia: Alan Emtage; Internet Hall of Fame: Alan Emtage
Google is named after a number
Larry Page and Sergey Brin first called their search engine Backrub. Soon it was renamed Google, a play on the word for the number 1 followed by 100 zeros, a googol. That word is much older than Google. It was made up in 1920 by a nine-year-old boy, Milton Sirotta, the nephew of the American mathematician Edward Kasner.
Why it fits here: The search engine that most of these operators are typed into began with a playful name for a very large number.
Sources: Google: Our story; Wikipedia: Google; Wikipedia: Googol
In one line
Quotes keep words together, minus removes a word's pages, site: searches one website, and the tool's name with its version narrows best of all.
Judging a source, and an answer
At a glance
Answers on the web are not equally trustworthy. The official docs of a tool come first, written by its builders for the current version. MDN and the language's specification follow. Then come Stack Overflow, with answers voted on by thousands of developers, and a project's GitHub issues. Blogs, videos, forums and chat groups can be the friendliest of all, but nobody checks them.
A good answer shows six signs. It explains why, it matches your situation, it is recent enough, others agree with it, it mentions its limits, and it survives your own test on an awkward value. Nothing is used until it has passed that last test.
Take a guess: Which deserves more trust: a friendly blog post from 2015, or the tool's own docs for your version?
When you ask for directions in a new town, you weigh the answers. The traffic policeman at the crossing is more reliable than a stranger who is not sure, and a signboard put up by the town is better still. Answers on the web differ in the same way, and a few checks tell you which to trust.
Sources, from the most to the least reliable
| Source | Why trust it | Watch out for |
|---|---|---|
| The official docs of the tool (nodejs.org, react.dev) | written by the people who build it, for the current version | pages for an older version: check the version at the top |
| MDN | a careful reference for the web and JavaScript, checked by many people | very new features may be marked Newly or Limited |
| The specification (ECMAScript) | the final word on how the language behaves | hard to read; use it to settle a detail, not to learn |
| Stack Overflow | real problems, answers voted on by thousands of developers | old answers, answers for another version or language |
| GitHub issues of the project | the builders and users of the tool discussing real bugs | long threads; the useful part is often near the end |
| Blogs and videos | friendly explanations, sometimes the best | no review: any slip stays; often written for an older version |
| Forums and chat groups | fast help from people | anyone can answer; nothing is checked |
Six signs of a good answer
- It explains why, not only what to type. An answer that only says "use this line" teaches nothing and may fit only the asker's case.
- It matches your situation: the same language, the same tool, the same kind of problem.
- It is recent enough, or says which version it is for.
- Others agree: it has votes, or several sources say the same.
- It mentions limits: when it does not work, and what to watch for.
- It survives your test: you run it on ordinary and awkward cases, and it holds.
The sixth sign is the only one you can check yourself, and it is the one that matters most. The first five help you decide which answer to test first.
Testing three answers
A well-known question on Stack Overflow asks how to round a number to 2 decimal places. Its answers, in our own words, suggest three ways. The first multiplies by 100, rounds, and divides by 100. The second uses toFixed(2) and turns the result back into a number. The third adds a tiny amount, called Number.EPSILON, before the first way, to fight the decimal surprise. Here they are on an ordinary value:
const x = 2.345;
console.log(Math.round(x * 100) / 100);
console.log(Number(x.toFixed(2)));
console.log(Math.round((x + Number.EPSILON) * 100) / 100);
2.35
2.35
2.35
Math.round is a job of the built-in Math helper: it rounds a number to the nearest whole number. All three ways agree on 2.345. Now an awkward value, 1.005, which should round to 1.01:
const x = 1.005;
console.log(Math.round(x * 100) / 100);
console.log(Number(x.toFixed(2)));
console.log(Math.round((x + Number.EPSILON) * 100) / 100);
1
1
1.01
The first two give 1, not 1.01. Why? Print the middle step:
console.log(1.005 * 100);
100.49999999999999
1.005 is stored a hair below 1.005, as lesson 4 showed for 2.55, so times 100 it is a hair below 100.5, and it rounds down. The third way adds a tiny amount first and gets 1.01. The test showed what the votes could not: two popular answers fail on a value that a shop might really meet.
What the test teaches
No way of rounding binary decimals is perfect for every value. For money, count in paise, as whole numbers, and divide by 100 only when printing. For other numbers, test the way you choose on the awkward values your program will meet.
Worked example 4
An answer you find says: "toFixed(2) rounds to 2 places, so const total = price.toFixed(2); then add the delivery charge to total." Judge it with the six signs and a test.
What we have: the answer, and what lesson 4 taught about toFixed's return value
What we need: a decision about using it
The plan: run its code with a price and a delivery charge, and check the type
const price = 199.999;
const total = price.toFixed(2);
console.log(total + 40);
console.log(typeof total);
200.0040
string
- Sign 6, the test, fails at once: total is a string, so + joined the charge on as text.
- Sign 5 fails too: the answer never mentions that toFixed returns text.
Do not use it as written. Round only when printing, or turn the result back into a number: Number(price.toFixed(2)) + 40.
Check: the test with a real delivery charge showed the slip in one run.
Another way: keep amounts in paise as whole numbers: 20000 paise plus 4000 paise is 24000 paise, printed as 240.00 rupees.
When you are stuck: too many answers that disagree
Rank them by source first: official docs and MDN above the rest.
Read the answers that explain why; skip the ones that only give a line to paste.
Test the top two on an ordinary value and on an awkward one.
Keep the one that passes, and note its limits.
Your turn
console.log(Math.round(2.4), Math.round(2.5), Math.round(2.6));
What does this print? Say your answer aloud first, then press Run or tap to reveal.Tap to reveal
2 3 3
- Math.round rounds to the nearest whole number.
- 2.5 is exactly halfway and rounds up to 3.
It prints 2 3 3.
Which of the six signs can you check entirely by yourself?Tap to reveal
- The other five depend on the answer's text or on other people.
The sixth: it survives your own test.
Why are blog posts lower on the list than MDN?Tap to reveal
- Think about who checks them.
Because nobody reviews them: a slip in a blog post stays, while MDN pages are checked by many people.
Did you know?
Out of date on the day they were posted
Answers on Stack Overflow can go out of date as tools change. In 2019 a team of researchers studied such obsolete answers. More than half of them, 58.4%, were probably already out of date on the day they were first posted. And once an obsolete answer had been spotted, only 20.5% of such answers were ever updated.
Why it fits here: This is why a good answer must be recent enough and must survive your own test, whatever its votes say.
Source: arXiv: An Empirical Study of Obsolete Answers on Stack Overflow (Zhang and others)
Wikipedia against Britannica
In December 2005 the science journal Nature published an investigation of the science entries in two encyclopaedias, Wikipedia and Encyclopaedia Britannica. It reported that Wikipedia came close to Britannica in the accuracy of its science entries. Britannica disputed the results and the way they were interpreted. Either way, both were judged by checking their entries against the facts, and not by their names.
Why it fits here: A source earns trust by being checked. The same holds for any answer met while searching: what does the evidence say?
In one line
Trust official docs and MDN first; prefer answers that explain why, fit your case, are recent and mention limits; and use nothing until it survives your own test on an awkward value.
Reading a project's bug list
At a glance
Most open-source projects keep a public register of their bugs, questions and requests. On GitHub it is the Issues tab of the project's page, and each entry is called an issue. An issue has a title, a state, open or closed, labels such as bug or question, and a thread of comments.
When a message comes from a library and not from JavaScript itself, the project's issues are often the best place to look, because the people who wrote the library answer there. Read the state, the labels and the last comments first. Look for a workaround, or for the version that fixes the bug, and add a thumbs-up instead of writing +1.
Take a guess: An issue says it was closed as completed: what does that tell you about the bug?
A railway station keeps a complaints register. Each complaint has a number, a date, what went wrong, the officer's reply, and finally whether it was solved. A software project keeps the same kind of register, open to everyone. On GitHub, where most open-source code lives, it is the Issues tab of the project's page.
One entry in a project's register of bugs, questions and requests. It has a title, a state (open or closed), labels, and a thread of comments.
When a message comes from a library rather than from JavaScript itself, the project's issues are often the best place to look, because the people who wrote the library answer there. Here is a made-up issue in the usual layout, for a made-up date library:
Title: padDate() puts undefined in place of the year
State: Closed (completed)
Labels: bug, good first issue
#1 reported by meera-k
Steps: call padDate(2026, 1, 26). Expected "2026-01-26", got "undefined-01-26".
Version: 4.2.0, Node 22.23.1
#2 maintainer
Thanks, reproduced. The year is read from the wrong argument.
#3 arjun-s
Workaround until a fix: pass the year as text, padDate("2026", 1, 26).
#4 maintainer
Fixed in pull request #318, released in 4.2.1.
| Part | Here | What it tells you |
|---|---|---|
| Title | padDate() puts undefined in place of the year | the problem in one line; compare it with yours |
| State | Closed (completed) | Open: not solved yet. Closed as completed: fixed. Closed as not planned: the project decided not to change it |
| Labels | bug, good first issue | the project's own sorting: bug, question, duplicate, and so on; good first issue marks easy ones for new contributors |
| The report | steps, expected, got, versions | a good bug report: notice that it follows the method of lesson 3 |
| The replies | reproduced; the cause | the maintainer, who keeps the project, confirms it |
| A workaround | pass the year as text | a way to avoid the bug until the fix arrives |
| The fix | pull request #318, released in 4.2.1 | the version that fixes it; a pull request is a proposed change to the code, taught in the Git step |
Read the last comments first. Long threads often go round in circles for fifty comments before someone posts the fix or the version that solves it. Then go back to the top only if the end is not enough.
Searching a project's issues
The search box of a project's Issues tab takes its own short instructions. is:open shows only unsolved issues, is:closed only solved ones, and label:bug only those labelled bug. Type the fixed words of your error with them, such as is:issue "returns undefined".
A common mistake
Writing a new comment that only says "+1" or "same here". It sends a notice to everyone following the issue and adds nothing. GitHub has a reaction button for that: a thumbs-up on the first comment counts you in without disturbing anyone. Comment only when you add something: a new detail, your versions, a workaround.
Worked example 5
You meet the same padDate bug, and your project has version 4.2.0 of the library. Using the sample issue, what do you do?
What we have: the issue above, closed as completed, fixed in 4.2.1
What we need: the right action
The plan: read the state and the last comment, then compare versions
- The state is Closed (completed): it was fixed.
- The last comment says the fix was released in 4.2.1.
- Your version, 4.2.0, is older. From 4.2.0 to 4.2.1 only the patch number goes up: fixes only, by the rule of lesson 4.
Update the library to 4.2.1 or later; until you can, use the workaround from the third comment.
Check: the update is a patch, so by semantic versioning it should break nothing else.
Worked example 6
Your search finds an issue with your exact error, but it is Open, two years old, and the last comment is "any update?". What now?
What we have: an old open issue with no fix
What we need: a way forward
The plan: look for a workaround in the thread, check whether a newer version changed things, and add only useful information
- Read the thread for a workaround; people often post one even when no fix exists.
- Check the project's newest version: the problem may have changed or gone, and the issue was never closed.
- If you have something new, such as a smallest example on the newest version, add it as one comment. If not, add a thumbs-up reaction.
Use a workaround if there is one, test the newest version, and add only new information, never "any update?".
Check: each step either solves your problem or makes the issue more useful to the people who can fix it.
When you are stuck: a long issue thread
Read the state and the labels first.
Then read the last five comments: fixes and versions are usually there.
Search the page for words such as workaround, fixed in or released.
Only then read from the top.
Your turn
What is the difference between an issue closed as completed and one closed as not planned?Tap to reveal
- Both are closed, for different reasons.
Completed: it was fixed. Not planned: the project chose not to change it.
What is a workaround?Tap to reveal
- The third comment of the sample issue gave one.
A way to avoid the bug until the real fix arrives.
Which search finds only unsolved issues labelled bug?Tap to reveal
- Combine the two instructions.
is:open label:bug.
Did you know?
The letter that brought the thumbs-up
A group of people who look after open-source projects once wrote an open letter called Dear GitHub. One complaint was that issues fill up with comments that say only +1, which serve only to spam the maintainers and everyone following the issue. On 10 March 2016 GitHub added reactions: small emoji, such as a thumbs-up, that anyone can add to a comment without writing a new one. GitHub said they would reduce the noise in long threads.
Why it fits here: That is why a thumbs-up, and not a +1 comment, is the polite way to say that an issue affects you too.
Sources: GitHub: dear-github, the open letter; The GitHub Blog: Add Reactions to Pull Requests, Issues, and Comments
Heartbleed, and the version that fixed it
In 2014 a serious bug was found in OpenSSL, a popular library of code for the encryption that secures connections on the internet. It was found independently by engineers at a company called Codenomicon and by Neel Mehta of Google Security, and it was named Heartbleed. Versions 1.0.1 to 1.0.1f were affected. Version 1.0.1g, released on 7 April 2014, fixed it, so the advice was short: use 1.0.1g or newer.
Why it fits here: An issue that names the fixing version gives the fastest answer of all: move to that version, and the bug is gone.
In one line
A project's issues are its public bug register: read the state, the labels and the last comments first, look for the version that fixes it or a workaround, and react with a thumbs-up instead of writing +1.
Writing a question people want to answer
At a glance
The people who answer questions on forums are volunteers, and they choose which questions to answer. A question they can understand in thirty seconds and run in a minute gets answered quickly. A question that makes them guess gets skipped.
A good question has a title that states the problem, what was expected and what happened, and the smallest example that shows the bug, written as text and not as a photo. It gives the versions in use, what was already tried, and one clear question. After asking, answer follow-up questions quickly, test the answer, and mark the one that solved it.
Take a guess: Why does a photo of code get fewer answers than the same code pasted as text?
Think of the people who answer questions on forums as volunteers at a help desk. They help in their spare time, and they choose which questions to answer. A question they can understand in thirty seconds and run in one minute gets answered within the hour. A question that makes them guess gets skipped.
A question that gets skipped
URGENT please help!!! my code not working
I am making a shop app and the total is wrong. I tried many things.
Please tell me what is wrong. (photo of the screen attached)
It says nothing a helper can use: no code, no values, no versions, and a photo of code that nobody can copy and run. "Urgent" and "many things" add pressure and no information.
A question that gets answered
Title: "4" + 455 gives 4455 instead of the sum when the quantity comes from a text box
I expected a bill of 1850 (4 tickets at 455 plus a fee of 30),
but the program prints 445530.
Smallest example (Node 22.23.1):
const qty = "4";
const fare = 455;
console.log(qty + fare * 1 + 30); // prints 445530, expected 1850
I checked that fare is a number (typeof fare is "number").
Why does + join the values here, and what is the right way to add them?
It has every part a helper needs. Its smallest example really shows the bug: run it here and you get the same number.
const qty = "4";
const fare = 455;
console.log(qty + fare * 1 + 30);
445530
| Part of a good question | In the example | Why it matters |
|---|---|---|
| A title that states the problem | "4" + 455 gives 4455 instead of the sum... | helpers choose from the title; people with the same problem find it later |
| What you expected, and what happened | expected 1850, got 445530 | step 2 of the method: it tells the helper exactly what is wrong |
| The smallest example, as text | three lines that show it | anyone can copy and run it; a photo cannot be run |
| Versions | Node 22.23.1 | answers differ between versions |
| What you tried | checked that fare is a number | saves the helper from suggesting it, and shows you did your part |
| One clear question | why does + join, and what is the right way | the helper knows when the answer is complete |
Code as text, in a code block
On Stack Overflow, GitHub and most forums, code goes between lines of three backticks, or is indented by four spaces, as in the good example. The site then shows it in a fixed-width font and keeps every space. Never paste a photo of code.
After you ask
- Answer follow-up questions quickly: a helper who asks for your version is close to a solution.
- Test the answer before you thank, with the checks of this lesson's judging section.
- Mark the answer that solved it (on Stack Overflow, accept it; on GitHub, say which comment fixed it), so that the next person finds it fast.
- If you solve it yourself, post the solution as an answer. Somebody will search for the same problem next year.
Before you post
Search first: many questions have been answered already, and a duplicate is closed at once. And check the example for secrets, names and private data once more; the question is public for ever.
Worked example 7
Turn this weak question into a good one: "toFixed broken?? My price shows wrong after adding delivery, help." The program behind it is the delivery bill from this lesson's judging section.
What we have: the weak question and the program it is about
What we need: a question with a clear title, the four things and a runnable smallest example
The plan: write the title as the problem; give expected and actual values; cut the code to the lines that show it; add the version and what was tried
- Title: toFixed(2) + 40 gives 200.0040 instead of 240.00
- Expected 240.00 (a price of 199.999 rounded to 200.00, plus a delivery charge of 40); got 200.0040.
const price = 199.999;
const total = price.toFixed(2);
console.log(total + 40);
200.0040
- Node 22.23.1. Tried: printing typeof total gives string.
- Question: why is the delivery charge joined on, and how do I add it as a number?
A title that states the problem, expected 240.00 and got 200.0040, three lines that show it, the version, what was tried, and one question.
Check: a helper can copy the three lines, see 200.0040, and answer in a minute; the asker's own typeof test already points at the cause.
Worked example 8
You asked a question yesterday, and this morning you found the answer yourself: the quantity was text. What do you do?
What we have: a solved problem and an open question
What we need: the right last step
The plan: think of the next person who searches for the same thing
- The question is still open, and others will find it by its title.
- Write an answer: the cause (the quantity came as text, so + joined), the fix (
Number(qty)), and a line of code.
Post your own answer, and mark it as the solution if the site allows.
Check: the next person with the same title finds the cause and the fix in one place.
When you are stuck: writing a question
Fill in four lines first: I expected; I got; here is the smallest code that shows it; I tried.
Run your smallest example once more, as text, to be sure it shows the bug.
Write the title last, as the problem in one line.
Your turn
Why should code in a question be text, never a photo?Tap to reveal
- Think about what the helper does with it first.
Because a helper must copy and run it, and nobody can run a photo.
Which is the better title: "Help with JavaScript" or "padStart(5, 0) returns the string unchanged"?Tap to reveal
- A title should state the problem.
The second: it states the exact problem, so the right helpers open it and the right searchers find it.
You solved your own problem after posting. What is the kind thing to do?Tap to reveal
- Someone will search for it later.
Post the solution as an answer.
Did you know?
The XY problem
Helpers have a name for a common trap: the XY problem. Someone wants to do X, does not know how, and guesses that some step Y will get them there. Then they ask only about Y. The helpers are puzzled, because Y seems a strange thing to want, and much time is wasted before the real goal, X, comes out. The idea goes back to Eric S. Raymond's guide, How To Ask Questions The Smart Way.
Why it fits here: A good question states the real goal, what was expected and what happened, so that helpers can see X and not only Y.
Sources: Greg's Wiki: XyProblem; Wikipedia: XY problem
Why the example must be short
Programmers have a name for the small example that a good question needs: an SSCCE, a Short, Self Contained, Correct Example. The guide that explains it, at sscce.org, takes each word in turn: short, so the reader is not bored; self contained, so everything needed is included; correct, so it can be copied, pasted and run. It warns that on a public forum most readers stop reading by 100 lines of code. Stack Overflow calls the same thing a minimal, reproducible example.
Why it fits here: The smallest example of this topic is exactly this: short enough to read at once, and complete enough to run.
Sources: sscce.org: Short, Self Contained, Correct Example; Stack Overflow Help Center: How to create a Minimal, Reproducible Example
In one line
A good question has a title that states the problem, expected and actual values, a runnable smallest example as text, versions, what you tried and one clear question; afterwards, test the answer and mark what solved it.
Understanding an answer's code before you use it
At a glance
Code copied from an answer goes into your own program, and on the day it fails, only understanding shows where to look. So before using it, take it apart from the inside out, like a set of boxes inside boxes. Open the innermost brackets first and print each piece with a label, until every piece has a meaning.
Look up every name you do not know, such as Number.EPSILON, on its reference page. Then rewrite the code with your own names, so that each line says what it does. Keep a comment with a link to the answer, so that its source can be found again.
Take a guess: If an answer's code works the first time, is there any reason to take it apart?
A good doctor does not give you a medicine she cannot explain. She knows what is in it and why. Code from an answer deserves the same care: before it goes into your program, you should be able to say what each piece does. Otherwise, on the day it fails, you will not know where to look.
Inside out, one piece at a time
Long expressions are built from short ones, like a set of boxes inside boxes. Open the innermost box first. Here is the rounding line from the judging section:
const x = 1.005;
console.log(Math.round((x + Number.EPSILON) * 100) / 100);
1.01
Take it apart from the inside, printing each piece with a label:
const x = 1.005;
console.log("1. the tiny amount:", Number.EPSILON);
console.log("2. x plus it:", x + Number.EPSILON);
console.log("3. times 100:", (x + Number.EPSILON) * 100);
console.log("4. rounded:", Math.round((x + Number.EPSILON) * 100));
console.log("5. divided by 100:", Math.round((x + Number.EPSILON) * 100) / 100);
1. the tiny amount: 2.220446049250313e-16
2. x plus it: 1.0050000000000001
3. times 100: 100.50000000000001
4. rounded: 101
5. divided by 100: 1.01
Now every piece has a meaning. Number.EPSILON is a tiny number, about 2.2 × 10⁻¹⁶; the e-16 in the output means "times ten to the power minus 16". Added to 1.005, it nudges the stored value just above the halfway point. Times 100 gives just over 100.5, which rounds up to 101, and 101 ÷ 100 is 1.01. Without the nudge, step 3 would be 100.49999999999999 and round down.
Look up every name you do not know
Number.EPSILON was new here. Its MDN page says it is the difference between 1 and the smallest number greater than 1 that can be stored. You do not need to master that today; you need to know it is a tiny fixed amount, and why the answer adds it.
Rewrite it in your own names
Once you understand it, rewrite the code in your own words, with names that say what each step is. You will remember it, and the next reader will understand it.
const amount = 1.005;
const nudged = amount + Number.EPSILON;
const paise = Math.round(nudged * 100);
const rupees = paise / 100;
console.log(rupees);
1.01
Same result, and each line now explains itself. Keep a comment with a link to the answer you learned it from; Stack Overflow's terms ask for credit when you copy code from it, and the link lets you check the answer again later.
Worked example 9
An answer says that "5" * 1 is a quick way to turn text into a number. Before using it, take it apart and compare it with Number(...).
What we have: a short expression whose meaning is hidden
What we need: what it does, and whether to use it
The plan: run the pieces and the alternative on ordinary and awkward values
console.log("5" * 1, typeof ("5" * 1));
console.log("abc" * 1, Number("abc"));
console.log("" * 1, Number(""));
5 number
NaN NaN
0 0
- Times 1 works by coercion: * only does arithmetic, so the text is turned into a number first (lesson 1).
- On awkward values it behaves exactly like Number: NaN for words, 0 for empty text.
It works the same as Number("5"); prefer Number(...), because it says what it does.
Check: both gave the same results on all three values, so the only difference is how easy the line is to read.
Worked example 10
An answer gives "Rs " + (price * qty).toFixed(2).padStart(10) to print a price column. Take it apart and say what each piece does.
What we have: a chain of four steps in one line
What we need: the meaning of each step
The plan: start from the innermost brackets and print each step
const price = 45.5;
const qty = 3;
console.log("1:", price * qty);
console.log("2:", (price * qty).toFixed(2));
console.log("3:", "[" + (price * qty).toFixed(2).padStart(10) + "]");
console.log("4:", "Rs " + (price * qty).toFixed(2).padStart(10));
1: 136.5
2: 136.50
3: [ 136.50]
4: Rs 136.50
- Step 1 multiplies. Step 2 rounds to 2 places as text. Step 3 pads it with spaces to 10 characters, so prices line up on the right. Step 4 joins the label in front.
Multiply, round to 2 places as text, pad to 10 characters, add the label.
Check: the brackets in step 3 show the four spaces of padding, and 136.50 plus 4 spaces is 10 characters.
When you are stuck: code you do not understand
Find the innermost brackets. Print that piece alone, with a label.
Move one step outward and print again, until the whole line is printed.
Look up every name you do not know on MDN.
Rewrite it in your own names, one step per line, and check it gives the same result.
Your turn
console.log((2 + 3) * 4, 2 + 3 * 4);
What does this print? Say your answer aloud first, then press Run or tap to reveal.Tap to reveal
20 14
- Inside the brackets first: 2 + 3 is 5, then 5 × 4 is 20.
- Without brackets, 3 × 4 is 12 first, then 2 + 12 is 14.
It prints 20 14.
What does e-16 mean in 2.220446049250313e-16?Tap to reveal
- e is short for "times ten to the power".
Times ten to the power minus 16: a very small number, about 0.0000000000000002.
Why rewrite an answer's code in your own names?Tap to reveal
- Think of the reader in six months, maybe you.
So that each line says what it does, and you remember why the code works.
Did you know?
The most copied snippet had a bug
A study published in 2018 looked at how code from Stack Overflow ends up in projects on GitHub. At the top of its list of the most frequently referenced Java answers was a short method that turns a number of bytes into readable text, such as 1.0 kB for 1024 bytes. A 2019 report said it had been copied into more than 6000 GitHub Java projects. That year its own author, Andreas Lundblad, admitted that it was flawed and published a corrected version.
Why it fits here: Code that runs is not always right. Taking it apart and testing each piece is how such a flaw gets noticed before it is copied again.
Sources: arXiv: Usage and Attribution of Stack Overflow Code Snippets in GitHub Projects (Baltes and Diehl); arXiv: Usage and Attribution of Stack Overflow Code Snippets in GitHub Projects (Baltes and Diehl); ZDNet: The most copied StackOverflow Java code snippet contains a bug
Unsafe code, copied into apps
In 2017 a team of researchers scanned about 13 lakh (1.3 million) Android apps on Google Play for code copied from Stack Overflow. They found that 15.4% of the apps held code about security taken from the site, and that 97.9% of those apps contained at least one insecure snippet. Their paper asked, in its very title, whether Stack Overflow should be considered harmful.
Why it fits here: Code that works can still be unsafe. Understanding each piece before using it is how the weak part gets noticed.
In one line
Before using code from an answer, take it apart from the innermost brackets out, printing each piece; look up every unknown name, rewrite it in your own names, and keep a link to its source.
Where it is used
Finding answers and asking well are part of every developer's day. These are the places the skills of this lesson turn up.
| What you learned | Where it is used | A real example |
|---|---|---|
| search operators | every search for an error or a method | site:github.com plus a library's error message finds the project's own issue about it in one search |
| ranking sources | choosing what to believe | a team rule: decisions about a tool's behaviour cite its official docs, not a blog |
| the six signs, and testing answers | every piece of code taken from elsewhere | a rounding answer with thousands of votes fails on 1.005; a test on awkward values catches it before customers do |
| reading issues | every library a project depends on | a build breaks after an update; the library's issues show a fix in the next patch and a workaround until then |
| writing a question | forums, Stack Overflow, a team's chat, a ticket for another team | a clear question with a smallest example gets an answer the same day from a stranger in another country |
| understanding code before using it | code review (the Git step) | a reviewer asks "what does this line do?"; an author who took it apart can answer at once |
| crediting sources | open-source licences | a comment with the link to the answer a line came from, as Stack Overflow's terms ask |
Mistakes and debugging
These are the habits that make searching slow and questions go unanswered.
1. Pasting the first answer
The first result is the most popular, not always the right one for you. The fix: check the six signs, and test it on an awkward value, as the judging section did with 1.005.
2. Searching in full sentences
"Why does my JavaScript program not add the numbers properly" matches pages that use those everyday words. The fix: search the exact message or the exact behaviour, in quotes, with the language: javascript "+" joins numbers string.
3. Asking without the smallest example
A question without code makes helpers guess. The fix: the smallest example from lesson 3, as text, run once more before posting.
4. Ignoring the date
An answer from ten years ago may use features since replaced, or miss ones added since. The fix: check the date, check whether a newer answer exists further down, and compare with the official docs for your version.
5. Using code you cannot explain
const x = "7";
console.log(+x + 1, x + 1);
8 71
A plus sign in front of a value, +x, turns text into a number: it is a short form some answers use. If you paste it without knowing that, the line next to it, x + 1, looks the same to you and does something else. The fix: take it apart until you can say what each piece does, and prefer the form that says what it does, Number(x).
The debugging corner: search your own notes first
Keep the one-line notes from lesson 4's routine and the bug diary from lesson 3 in one file. Before searching the web, search that file. The bug you are stuck on today is often one you solved last month.
Quick card
The lesson on one card.
| To | Do |
|---|---|
| keep words together | put them in quotes: "missing ) after argument list" |
| remove a family of wrong results | minus: -python |
| search one trusted site | site:developer.mozilla.org, site:github.com |
| narrow to your version | add the tool and its major version: node 22 |
| judge an answer | explains why, fits your case, recent, others agree, mentions limits, survives your test |
| read an issue | state and labels, then the last comments: the fix, its version, a workaround |
| search a project's issues | is:open, is:closed, label:bug |
| ask a question | title as the problem; expected and got; smallest example as text; versions; what you tried; one question |
| understand code | inside out, printing each piece; look up unknown names; rewrite in your own names; keep the link |
Taking an answer apart
// an answer taken apart, one labelled print per step
const amount = 1.005;
console.log("nudged:", amount + Number.EPSILON);
console.log("rupees:", Math.round((amount + Number.EPSILON) * 100) / 100);
nudged: 1.0050000000000001
rupees: 1.01
The story: A note worth pinning
You search the board with care, using the clock's exact model and the exact words it prints. Two notes match. The confident one is for a different clock. The quiet one, signed by Ledger of the Society, was tested, and explains why the chime runs twice. You try it, and it works.
Then you pin a note of your own for the next apprentice: what you tried, what happened, the clock's version, and the fix.
Corin reads it twice. "That is the first note on this board I understood at once," he says.
Reagents gathered: search operator, issue, pull request, smallest example.
Sources
- MDN Web Docs (Prose CC BY-SA 2.5 or later; code samples added since 2010-08-20 CC0 (its licensing page, read 2026-10-26); reused with credit)
- Stack Overflow (Not confirmed from the site (its help page could not be fetched, 2026-10-26); facts and ideas only)
- The ECMAScript language specification (ECMA-262) (Ecma International copyright; facts and ideas only)