Reading Errors and Tracing Execution
An error message is evidence about a problem. Read its type, message, file, and line before changing code. The reported line shows where the problem surfaced; its cause may be earlier.
Recognize the problem
| Category | What happens | Common cause |
|---|---|---|
| Syntax error | JavaScript cannot parse the affected script. | An unmatched bracket or unfinished string. |
| Runtime error | An error occurs while code is executing. | Accessing a property of null, or using an undeclared variable. |
| Logic error | Code runs but produces the wrong result. | An incorrect condition, string arithmetic, or updating the wrong item. |
A misspelled variable name can produce a runtime ReferenceError; it is not automatically a syntax error. Code can also be wrong without any console error.
Trace the sequence
Follow the user action into its handler. Check the input value and type, the condition taken, the data before and after the change, and the function that updates the page. For asynchronous work, distinguish starting a request from receiving its result.
Write down expected and actual behaviour. Reproduce the problem with the smallest reliable sequence. Fix one suspected cause, then repeat the same sequence to check the result.
Checklist
- [ ] I can reproduce the problem.
- [ ] I recorded expected and actual results.
- [ ] I read the message and inspected the relevant source line.
- [ ] I checked input types, conditions, and state changes.
- [ ] I tested whether the fix addresses the cause.