DEV Community

Cover image for What are the different types of errors in JavaScript?
Senichi
Senichi

Posted on • Updated on

What are the different types of errors in JavaScript?

Errors are statements which don't let the program run properly. There are three main types of errors that can occur while compiling a JavaScript program. These errors include syntax errors, runtime errors, and logical errors.

  • 1. Syntax Errors (most common)

Incorrect syntax raises parsing errors and occur at the interpretation time. Simple example is to introduce a semicolon where a double-colon it's needed.

let exObj = { name; 'Rick' }
Enter fullscreen mode Exit fullscreen mode

  • 2. Runtime Errors

Occur after the compiler interpret the code, when the code ran. Also known as exceptions. It can occur by calling a function that It wasn't declared.

The syntax is correct but the function is not present.

// calling not declared function
doSomeStuff()
Enter fullscreen mode Exit fullscreen mode

  • 3. Logical Errors (most difficult to find)

Error in the flow of data. The logical elements are well structured, the syntax is correct, but the confluence of data lands improperly.

Consider the script "There is a movie called Terminator 2". Consider the happy ending statement path: ''John Connor kills Terminator.''

Now consider a logical error: ''Terminator kills John Connor.''

These kind of errors change how your program should work from the result we would expect.


Synthesis

  1. syntax errors : while interpretation. Simple example: misspelling.
  2. runtime errors: while execution. Simple example: due to misuse.
  3. logical errors: scrambled logical perform. Simple example: ''Terminator kills John Connor.''

Top comments (1)

Collapse
 
frankfont profile image
Frank Font

Senichi, I would add dev.to/frankfont/look-professional... as a good way to quickly debug logical errors --- even after shipping.