Errors
Errors are a normal part of programming. Understanding them helps you debug faster.
Common Error Types
SyntaxError
Invalid JavaScript syntax — code can't even be parsed.
// SyntaxError: Unexpected token
console.log('hello'
// Missing closing parenthesis
ReferenceError
Accessing a variable that doesn't exist.
console.log(myUndefinedVar)
// ReferenceError: myUndefinedVar is not defined
TypeError
Performing an operation on the wrong type.
null.property
// TypeError: Cannot read properties of null
Reading Error Messages
Error messages have three key parts:
- Error type — what category of error
- Message — what went wrong
- Stack trace — where it happened (file name + line number)
💡 Debugging History
The word "bug" in programming comes from 1878 when Thomas Edison used it to describe technical glitches. The first actual computer bug was a moth found in a relay of the Harvard Mark II computer in 1947.