Browser DevTools and the JavaScript Console
By the end of this lesson, you'll be able to:
- Use the Console panel to read errors and inspect logged values
- Use the Elements panel to inspect a component's rendered Shadow DOM
- Use the Sources panel to set breakpoints and step through component code
Prerequisites: Module 14: "Apex Tests for Controllers and Services"
The Console Panel
A genuine JavaScript error in a component almost always shows up in the Console panel first, complete with a stack trace pointing to the offending line. console.log()/console.error() statements placed deliberately in component code are a quick way to inspect a value's actual state during development — simple, but often the fastest first step when something behaves unexpectedly.
The Elements Panel and Shadow DOM
The Elements panel shows a component's actual rendered markup — including its Shadow DOM boundary (Module 1), visible as a #shadow-root marker in the tree. This is how to verify what a component genuinely rendered, versus what the template should have produced — a real discrepancy here often points straight at the bug.
Sources Panel and Breakpoints
Setting a breakpoint directly on a line of component JavaScript in the Sources panel pauses execution there, letting variable values be inspected live at that exact moment — often considerably faster than sprinkling console.log statements throughout the code and re-running repeatedly to narrow down a problem.
Recap: The Performance Panel
Module 13 covered the Performance panel in depth as the specialized tool for profiling slow components — worth remembering as part of the same DevTools toolkit, reached for specifically when the problem is speed rather than correctness.
Exercise
A component's button click seems to do nothing. Describe, as a comment, the first DevTools panel to check and why.
Show hint
Think about where an unhandled JavaScript error would surface.
Exercise
Challenge: explain, as a comment, why setting a breakpoint can be faster than adding several console.log statements to diagnose a bug.
Show hint
Think about how many times each approach requires re-running the code.
Browser DevTools and the JavaScript Console Quiz
My Notes
Log in to keep private notes on this lesson.
Questions about this lesson
No questions yet — be the first to ask.
Log in to ask a question about this lesson.
Summary
Browser DevTools are the first stop for any client-side LWC problem — the Console for errors, Elements for rendered markup, and Sources for stepping through code live.