5 exercises — developers who mix up error types sound imprecise in code reviews, incident reports, and interviews. Naming the error type correctly shows technical fluency.
The four error type categories
Syntax error — violates language grammar; caught before execution (parser, compiler, IDE)
Semantic / Type error — valid grammar, wrong meaning or types; caught by type system or compiler
Runtime error — the program crashes during execution (null reference, stack overflow, divide by zero)
Logic error — runs without crashing; produces wrong output; only caught by tests or humans
0 / 5 completed
1 / 5
The terminal prints:
SyntaxError: Unexpected token '}' (line 47)
The developer has not run the program yet — this message appeared immediately when loading the file. Which error type is this?
Syntax error — a violation of the language's grammar rules, caught by the parser or compiler before the program runs. The code cannot even be parsed. Examples: missing closing bracket, unmatched quotes, misspelled keyword (funciton instead of function). Error messages often say: SyntaxError, ParseError, unexpected token. In interpreted languages (Python, JavaScript), syntax errors are caught when the interpreter first reads the file. In compiled languages (Java, C++), they are caught at compile time. Key indicator: "it failed before I ran it" → almost certainly a syntax error. The four error type categories: Syntax (grammar) → Semantic/Type (meaning/types) → Runtime (crash during execution) → Logic (wrong output, no crash).
2 / 5
A developer writes a function to calculate the area of a circle:
function circleArea(r) { return 2 * Math.PI * r; }
The code runs without any error message. However, all the results are wrong. What type of error is this?
Logic error — the code is syntactically correct, compiles/runs without crashing, but produces incorrect results because the algorithm itself is wrong. The correct formula is Math.PI * r * r (area = πr²); the code uses 2 * Math.PI * r (circumference formula). There is no error message. Logic errors are the hardest to find because the program does not crash — they are only discovered by testing against expected outputs, code review, or catching unexpected behavior in production. Examples of logic errors: off-by-one errors (< vs <=), wrong operator (&& vs ||), wrong formula, swapped conditions, missing edge case. Tool for finding them: unit tests with assertions that check the actual expected output, not just "did it crash".
3 / 5
During a production incident, an alert fires:
TypeError: Cannot read properties of null (reading 'split')
The code had been running fine for months. Today, one specific API response returned null instead of a string, and the code crashed. What type of error is this?
Runtime error — occurs during program execution, not during parsing or compilation. The code is syntactically valid and the types may look fine statically, but at runtime something unexpected happens (null reference, division by zero, stack overflow, out-of-memory, network timeout). Common runtime errors: NullPointerException / TypeError on null, ArrayIndexOutOfBoundsException, StackOverflowError (infinite recursion), IOException (file not found), UnhandledPromiseRejection. Important nuance: You could also argue there is a logic error (failure to validate the API response). In engineering practice, one bug can be described from multiple perspectives — the immediate error is a runtime crash (RuntimeError), but the root cause is a logic error (missing null check). In most technical discussions, "runtime error" refers to the category of crash-at-execution-time errors. Defensive pattern: always validate data from external sources before using it.
The IDE underlines greet(42) before you even run the file. What type of error is this?
Semantic error / Type error — the code is syntactically correct (valid expression), but it violates the meaning or type contract of the language. In TypeScript and other statically-typed languages, the type system catches these errors at compile time (or in the IDE, before you run). The error: Argument of type 'number' is not assignable to parameter of type 'string'. Semantic errors are sometimes called type errors in typed languages. They differ from syntax errors (wrong grammar) and logic errors (wrong algorithm). In dynamic languages (plain JavaScript, Python without type hints), this would instead be a runtime error — no type check happens until execution. The four categories in context:Syntax = bad grammar (parser catches it); Semantic/Type = bad types/meanings (type system or compiler catches it); Runtime = crashes during execution; Logic = wrong output, no crash.
5 / 5
A sorting function runs successfully and returns a result. The QA engineer reports: "The list is sorted, but in descending order instead of ascending order as specified in the requirements." What type of error is this?
Logic error — the most common category in real-world software bugs. The code compiles, runs, and does not crash — but it produces an output that does not match the specification. In this case, the developer likely wrote b - a instead of a - b in the comparator (or > instead of <), reversing the sort order. Logic errors are often the hardest to catch because: (1) no error message is produced, (2) the behavior looks right at a glance, (3) they require understanding the expected output to detect. How to prevent logic errors: Unit tests with explicit expected-output assertions, code reviews focused on business logic correctness, Test-Driven Development (TDD) where you write the expected output first. In interviews: "What types of bugs are hardest to find?" — logic errors, because tools (compilers, linters, type checkers) cannot detect them; only humans and tests can.