Lesson 4.2Lesson 17 of 24
The console and breakpoints
Given code to be debugged, use the console and breakpoints.
Key points
- 1Pick the console call by what you need to see: table for arrays of objects, dir for an object's properties, trace for the call path, count for how often.
- 2console.assert prints only when its condition is false, and console.time with timeEnd measures the time between two calls with the same label.
- 3In Chrome a logged object is shown live: when you expand it later, the console shows its current values. Log a copy or a string for a snapshot.
- 4A conditional breakpoint pauses only when its expression is true. A logpoint prints a message without pausing. Neither needs a code change.
- 5The debugger statement pauses like a breakpoint only while DevTools or another debugger is attached; otherwise it does nothing.
What the exam guide checks here
Objective wording from the exam guide (English).
- 4.2.K1console methods: log, info, warn, error, table, dir, assert, time, trace, group
- 4.2.K2Breakpoints, conditional breakpoints, the debugger statement, stepping
- 4.2.S1Choose the console call or breakpoint that reveals a given bug
Lock it in
Answer scenario questions on this topic. Every option comes with an explanation.
Practise 4.2 · 12 questions