What Happens When You Type a URL and Press Enter
DNS lookups, TCP and TLS handshakes, HTTP requests, servers, and the browser's rendering pipeline. The whole journey of a web page, explained so it finally clicks.
Read →Error messages look like noise until you know where to look. How to read the message, find your line in the stack trace, decode common errors, and turn a wall of red into a fix.
Beginners see a wall of red text and feel stuck. Experienced developers see the same wall and usually know where the problem is within seconds. They're not smarter; they've just learned where to look. You can learn that too, and it'll make you faster than almost any other single skill.
The most important information is almost always at the top: the error type and the message.
TypeError: Cannot read properties of undefined (reading 'map')
at ProductList (ProductList.jsx:14:22)
at renderWithHooks (react-dom.development.js:...)
...
Translate it into plain words before doing anything else:
.map on something that's undefined.So the real question is: what was I calling .map on, and why is it undefined? That's already 80% of the debugging.
A stack trace is a list of function calls, from where the error happened back up through everything that called it. Most lines belong to frameworks and libraries. Skip those and look for the first file you wrote:
at ProductList (ProductList.jsx:14:22)
That's file, line 14, column 22. Go there. In this example, it's probably products.map(...) where products hasn't loaded yet.
A few notes:
Caused by: lines. The root cause is often at the bottom of a chain of wrapped exceptions.a.js:1:28374) need source maps. Upload them to your error tracker so traces point to real files.| Message | What it usually means |
|---|---|
Cannot read properties of undefined (reading 'x') |
Something you expected to be an object isn't loaded or doesn't exist yet |
x is not a function |
Wrong import, typo, or the value isn't what you think it is |
x is not defined / NameError |
Variable never declared, out of scope, or misspelled |
Unexpected token < in JSON |
You asked for JSON but got HTML, usually a 404 or error page |
Module not found / Cannot find module |
Wrong path, missing install, or case mismatch in the filename |
EADDRINUSE |
Another process already uses that port |
ECONNREFUSED |
Nothing is listening at that address: service down, wrong host or port |
CORS policy |
Server didn't allow your origin (full explanation) |
relation "x" does not exist |
Table missing: migrations not run, or wrong database |
401 vs 403 |
401: not authenticated. 403: authenticated but not allowed |
500 Internal Server Error |
The real error is in the server logs, not the browser |
That Unexpected token < one deserves a special mention. It means the response started with <, as in <!DOCTYPE html>. Your fetch hit the wrong URL and got an HTML page back. Check the Network tab for the actual response.
Sometimes the error appears far from the actual cause.
undefined three calls earlier; the error happens where it's finally used. Trace the value backwards.If you don't see an error, you might be looking in the wrong place:
A common beginner trap: the UI shows "Something went wrong," the browser console is clean, and the real stack trace is sitting in the server terminal the whole time.
When you need to search, be smart about it:
"Hydration failed" next.js.Once you appreciate a good error message, you'll start writing them:
// Unhelpful
throw new Error('Invalid input')
// Helpful
throw new Error(`Expected "quantity" to be a positive integer, got ${JSON.stringify(quantity)}`)
State what was expected, what you got, and where possible, how to fix it. Your teammates and future self will thank you.
Next time you hit an error, before searching anything, try this:
Do that a few dozen times and it becomes reflex. Pair it with a systematic process and you'll handle bugs calmly: how to debug code systematically.
Start with the error type and message, then scan for the first line that references a file you wrote. That's usually where to start. In Python, the most relevant lines are at the bottom.
You're using a value that doesn't exist yet or was never set: data still loading, a typo in a property name, a function that didn't return anything, or a missing prop.
Your code tried to parse JSON, but the response was HTML, usually a 404 page or a server error page. Check the request URL and the actual response in the Network tab.
DNS lookups, TCP and TLS handshakes, HTTP requests, servers, and the browser's rendering pipeline. The whole journey of a web page, explained so it finally clicks.
Read →There are dozens of HTTP status codes, but about fifteen cover nearly everything. What each one means, when to return it, and the mix-ups (401 vs 403, 301 vs 302) that confuse everyone.
Read →A, AAAA, CNAME, MX, TXT and NS records in plain English, why DNS changes seem slow, and the troubleshooting commands that tell you what is really going on.
Read →