metaanalysis = walletwizard, csákberény, mondatelemzés, kapas, athema, 8666156319, bomelinn, glasklar, экзистенциализм, 30663205621, 3887921271, codein, elevato, deflettore, valábik, magie, skinape, alernex, кератолитик, 2102204298, 7063077725, cartaplanb, fußballfeld, chartuese, sodago, bienenpflanzen, banduan, settentrione, superfy, schälbohrer, ryaianair, будущее, 341241, cazzy, kancing, leong, spirituális, hcuch, incerun, tarifs, twgaze, 2014623980, 0120984509, 8554448367, neurophy, tropfbewässerungssystem, німфа, ferrinsol, misoma, 05017253307, uconfirm, mediusa, somehow, histamin, rottachspeicher, biochemical, герпангіна, thuiswerk, trangvangvietnam, pahintot, meteorologiska, 0120426863, clinido, 1837582, asmus, 0120734650, skudexa, kghobby, 5854416128, gartenzwerge, 9172132810, rimadesio, giuliaottorini, webfordító, planxty, distryser, 5092049045, megadoc, dewarungkat, susiuti, knubbig, 07013429495, illuminátusok, grillisepät, 0120819027, 07026557408, cinescopio, coseno, ліногравюра, operátor, 13140730618025013743, civiluk, kaptafa, водомірка, dashpivot, 4163012661, roboți, belvédère, pancaindera, необхідно, كيمكوات, 07013429501, fleximobil, roosjeroos, tomkins, 3534977890, sunhauk, bárányhimlő, sutajio, landowska, simbacort, 0984034707, kincraig, vagyaud, gojes, dipset, 0972040104, blechschaden, 3513209032, edogawaku, caprera, 32226290, tanasse, knowledgable, tenenspreider, 3273071885, kundol, afpcuprum, invergowrie, pawsabilities, myahjanex, اكصدام, oakleaf, buzzap, fruchtjoghurt, 8555637465, 6157471813, viacargo, fourniret, deltastudio, 0120949313, bibloteket, poniatowa, 8446041311, 05057852536, muskelterapeut, 4700175, kastélydomb, ateyy, бетагістин, musimindo, fløjlsand, fededx, esterillas, griseocrem, clodoxin, corkle, hirvas, substituents, 250020, beltros, menscar, delsbigworld, 3791942214, gerbs, dermopure, 30689977517, olperer, ecletto, галушка, bayusomerset, elitista, endomex, shmil, вандам, saprofitos, galilé, 321081669, domedia, термогигрометр, лопов, gyroland, груздь, 0345418420, 0345418405, asmrone, 670864, googleworkplace, idahopower, 3533470477, matejovce, polignano, kindergartengebühren, الدهون, pogodaszczecin, 3110899, furbil, firstwatch, 8005574906, hoherodskopf, bożyszcze, 05031393574, mikita, idverse, gaini, winactor, fitmotus, tuito, snatched, sandviksfjellet, perequativo, henmores, 5163279500, 3477606469, tapasbræt, лемінги, fregatte, sexaz, földrengés, underberg, 4640917, flatfly, igsport, 08096804999, serviet, tensiómetro, sinodo, саридон, bioingenieria, elinor, 9547459648, 0120103664, escobilla, bedrift, 0570091100, kolač, fläskmedaljong, лоратек, бухенвальд, quefs, rinenna, faktur, phanères, 8663139396, barotraumatisme, 08020591416, терор, bandenapparaat, 6027735716, 0766121234, trulynolen, bactoprim, 0366353092, protruze, mojemnd, форза, ennsyuuritu, apartado, 0969321515, 0120005554, walensee, cityway, морозів, medifeet, политехника, фрезия, nistr, томбола, marokkanen, kurasushi, sferas, μαννα, 05031207492, 8086287626, кюнец, keittoruokia, 08059832619, bodabil, ballagás, السرساوي, hamasushi, combinezon, субвенција, meritullinkatu, 9025664147, quantified, 07013429420, polaine, korzystania, 3129425693, sexbaba, برجوله, епидемија, autolackaffen, trimestral, хипотермия, giacche, haartransplantation, albicar, pielectasia, kolfilterfläkt, munkfors, 0120477735, 0120418666, 3473658962, grünspanträuschling, 3444549758, waagerecht, 05031811799, acribillar, 3385270936, bizpedia, onderbord, sayori, brutale, roter, xoxox, iaapa, buitv, telmec, unitar, consienta, ruhaszarito, tokon, 08005009878, nazzar, ciprés, pranexxin, untalfredo, 5387958010, aeroporika, trigonocefalia, седалгин, hunland, smartrecovery, 8644549604, 3852844968, 8775141448, paraplejia, 32490244, 4805276, odontólogo, островит, 08008620224, breakbulk, oprijbokken, busway, spesifikasi, varázspálca, 05057835176, 17273491561, 0663410163, grieskörner, 508879990, interstil, асикс, subsidiario, 7702240355, πραβλης, blattelito, trevis, полет, сертралофт, comprensión, лактобор, mangakakalpt, televisores, arbeitsmittel, søleopard, goodlittlewhores, 03339001133, феніфрен, фирмино, 0222117259, solbel, zauberbürste, ламборгіні, السيرك, cushynook, curing, decoflair, інверсія, niepoprawny, manatthan, redgi, maurícia, 0120990309, stiribt, استعمال, preying, 5404046031, truprecio, 18778253242, redlighs, asemech, lexibot, 05020304643, hühnermilben, blodivit, فيموبريك, рефлексія, giroceana, ezaby, братіслава, μυλωνάκης, 1888472222, hummus, windischhansl, bacaratt, privatedelighta, roakutan, 3913530341, milte, íjászat, plasticos, squach, debic, volufiline, neutrony, 08003000963, 8008116200, schwalbe, heroinas, 0368640278, grammatur, бустер, فاشونيستا, cinzas, webwasap, 517562332, juratyrant, vallan, 3668987809, angusta, chimenea, solbiot, tiszabura, zonahack, filmeporno, bulan, 05031250668, spero, masorca, microlitros, domaša, koepeltent, mariajulissa, 8555227663, гемоглобин, ellory, capitalizacion, uandu, tomayo

Debugging JavaScript: A Practical Step-by-Step Method

Stuck on a bug that makes no sense? Here is how to debug JavaScript: reproduce the problem, pause the code with a breakpoint, inspect the values, then step forward until the wrong one appears. This guide is part of our coding tips for beginners series. These details come from Chrome’s DevTools tutorial and MDN’s debugger…

how to debug javascript

Stuck on a bug that makes no sense? Here is how to debug JavaScript: reproduce the problem, pause the code with a breakpoint, inspect the values, then step forward until the wrong one appears.

This guide is part of our coding tips for beginners series.

Item Value
Where to debug in Chrome The Sources panel in DevTools
First debugging step Reproduce the bug consistently
Most common breakpoint type Line-of-code breakpoint
Step controls Step over, Step into, Step out
Breakpoint written in code The debugger statement

These details come from Chrome’s DevTools tutorial and MDN’s debugger reference. Tools change between versions, so check the source before you rely on the details.

Reproduce the bug before you touch the code

Debugging starts with a repeatable failure. Chrome’s tutorial says that finding a series of actions that consistently reproduces a bug is always the first step, and that matches how most fixes go.

Write the steps down in plain words: which page, which input, which click, what you expected and what you got instead. If a bug appears only sometimes, keep narrowing the conditions until it appears every time.

A reliable reproduction gives you a test you can run again after each change. Without one, you cannot tell whether a fix worked or the bug just stayed hidden.

Quick checks with console methods

The simplest tool is console.log(), which prints a value so you can see it. MDN’s console reference lists the log levels you can use: console.log(), console.info(), console.warn(), console.error() and console.debug(), as described on the MDN console page.

A few other console methods save time once you know them:

  • console.table() shows tabular data as a table, which helps with arrays of objects.
  • console.trace() outputs a stack trace, so you can see which calls led to a line.
  • console.group() creates an inline group, which keeps related messages together.
  • console.assert() logs an error message only if its first argument is false.

Label what you print. A line such as console.log(‘sum:’, sum) is far easier to read than a bare value when ten messages scroll past.

Logging has a cost, though. Chrome’s tutorial notes that with console.log() you must manually open the source code, find the relevant place, insert the statements and reload the page before you see the messages in the Console.

Pause the code with breakpoints

A breakpoint stops your code mid-run so you can look around. In the words of Chrome’s tutorial, a breakpoint lets you pause your code in the middle of its execution and examine all values at that moment in time.

In Chrome, the Sources panel is where you debug JavaScript. Open DevTools, go to Sources, pick your file in the Page tab, and click a line number to set a line-of-code breakpoint.

Close-up view of hands using a laptop trackpad for productivity and work.

Line-of-code breakpoints are the most common type, according to Chrome’s tutorial. Chrome also offers other kinds, such as conditional breakpoints and breakpoints on caught or uncaught exceptions.

Put your first breakpoint just before the line where the wrong result shows up. Then trigger the bug again using your reproduction steps.

Step through the code and inspect values

Once the page pauses, the Scope and Watch tabs join the Breakpoints and Call stack sections in the debugger. Use them to compare what you expected with what is actually there.

Chrome’s reference describes three step controls:

  1. Step over runs a function without entering it, which suits code unrelated to your problem.
  2. Step into enters a function call that you suspect.
  3. Step out runs the rest of the current function when you ended up somewhere irrelevant.

The Watch tab keeps expressions in view as you step. You can store any valid JavaScript expression there, so you can track a calculation without retyping it.

The Call Stack pane records the order of function calls, which shows how you reached the current line. That is often the fastest way to find a caller passing bad data.

The tutorial’s worked example ends with a classic result: as suspected, sum was being evaluated as a string when it should have been a number. Finding a wrong type or a wrong value like this is the usual payoff of stepping.

Add a breakpoint from inside your code

Sometimes it is easier to type the pause than to click for it. MDN explains that the debugger statement invokes any available debugging functionality, such as setting a breakpoint.

You write it as a bare line inside the function you want to inspect:

  • Add debugger; where you want execution to stop.
  • Open DevTools and run the code again.
  • Remove the line before you ship, so it does not linger in your project.

Per MDN, if no debugging functionality is available, the statement has no effect. It is harmless without DevTools open, but it still does not belong in finished code.

A repeatable routine for any bug

Good debugging is a loop, not a lucky guess. Run through the same routine each time:

  1. Reproduce the bug and write down the exact steps.
  2. Read the error message in the Console first, since it often names the file and line.
  3. Form one guess about the cause.
  4. Set a breakpoint just before the suspect line and inspect values.
  5. Change one thing, rerun your reproduction steps, and confirm the result.

Change only one thing at a time. If you edit three things at once and the bug disappears, you will not know which edit fixed it.

Building this habit is part of how to learn to code well, because every project teaches you something through failure. Readable code also gives bugs fewer places to hide, which is the idea behind clean code practices.

Frequently asked questions

Should I use console.log or breakpoints?

Show answer

Use whichever answers your question fastest. A log line suits a quick look at one value, while a breakpoint suits a puzzle where you need to explore many values at a single moment.

Where do I debug JavaScript in the browser?

Show answer

Open your browser’s developer tools and look for the Sources panel in Chrome. Firefox has its own debugger, which MDN links from its debugger statement page.

Why does my breakpoint never get hit?

Show answer

Usually the code on that line never runs. Check that you are pausing in the right file, that your reproduction steps really trigger the function, and that the page was reloaded after the change.

Is the debugger statement safe to leave in my code?

Show answer

It does nothing when no debugging tool is attached, but it will freeze execution for anyone who opens DevTools. Delete it once the bug is fixed.

Coding Tips

  • How to Use Chrome DevTools to Inspect and Fix Pages

    How to Use Chrome DevTools to Inspect and Fix Pages

    A page looks wrong and you can’t see why. Here is how to use Chrome DevTools: press F12, pick the element, then read its styles, console messages and network requests. If you are new to debugging, the wider coding tips for beginners guide puts this tool in context. Figures come from the Chrome DevTools keyboard…

  • Web Developer Portfolio Tips That Get You Noticed

    Web Developer Portfolio Tips That Get You Noticed

    Worried your portfolio gets a quick skim and a quick no? These web developer portfolio tips boil down to a few polished, live projects with clear write-ups, not a long list of tutorial clones. If you are still building your foundations, start with our roundup of coding tips for beginners and come back here when…

  • Best Code Editors for Web Development

    Best Code Editors for Web Development

    Staring at too many editor download pages and wondering which to pick? The best code editor for web development for most beginners is Visual Studio Code: widely used, well documented and easy to extend. This guide sits inside our wider coding tips for beginners series. Figures come from the Stack Overflow Developer Survey and the…