Errors and debugging
Read a stack trace, use the console deliberately and prevent silent failures.
What you will be able to do
- Distinguish error types
- Read a stack trace
- Validate at boundaries
Bugs are information. A clear error message with a stack trace tells you exactly where execution stopped. The skill is reading it calmly.
| Error | Usually means |
|---|---|
| SyntaxError | The code could not be parsed at all. |
| ReferenceError | You used a name that does not exist in scope. |
| TypeError | You called or accessed something on the wrong type. |
| RangeError | A value is outside the allowed range. |
function parseScore(raw) {
const score = Number(raw);
if (!Number.isFinite(score)) {
throw new TypeError(`Invalid score: ${raw}`);
}
if (score < 0 || score > 100) {
throw new RangeError("Score must be between 0 and 100");
}
return score;
}Your turn
EasyGuard the input
Throw a TypeError if email does not include "@", otherwise return the trimmed email.
JAVASCRIPT · starter
function validateEmail(email) {
// your code here
}Check your understanding before moving on.
Knowledge checkQuestion 1
What does a ReferenceError usually indicate?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.