← Trail· Lesson 9 of 10
See this lesson in TypeScript →
Debugging and edge cases
Read errors, inspect console values and fix an off-by-one loop.

Debugging investigates the gap between expected and observed behavior. Write your expectation, reproduce the issue and follow the values instead of randomly changing symbols.
| Error | Check first |
|---|---|
SyntaxError |
Parentheses, braces, quotes and statement structure |
ReferenceError |
Spelling, declaration and variable scope |
TypeError |
The value’s type and the operation attempted |
The message and line number provide a starting point; the cause may be a little earlier. Replacing a declared variable name with an undeclared one can cause ReferenceError. Read the Console message and use Resetar to restore the starter.
Logical errors
Not every bug throws. The example runs but returns 3 instead of 1 + 2 + 3 = 6. Its logs reveal which numbers entered the loop. Compare the last visited number with the limit.
Try it
Follow i and total. Add a log after the loop or set the limit to 1. Change one thing at a time.
Execute o código para ver a saída aqui.Exercise: include the final number
somarAte(limite) must sum integers from 1 through the limit, inclusive. The input is an integer; for zero or a negative limit, the interval is empty and the result is 0.
The starter excludes the final number. Fix its condition, keeping the counter update so the loop terminates. Verificar checks 1, 3, 5, zero and a negative value. Do not hardcode the answer for 3. Feedback is in Portuguese.
Execute o código para ver a saída aqui.Edite o JavaScript e clique em Verificar.
A debugging checklist
- Write the expected result.
- Use the smallest input that reproduces the issue.
- Inspect values with
console.log. - Fix one cause and run all checks again.
The final project combines these techniques in an average calculator.