JavaScript Debugging

It can be frustrating for new developers when their code doesn't work the way they expected. This maybe caused by a missing semi-colon, a mistyped variable name or an infinite loop. But ultimately, it is because they made a mistake. Making mistakes can be frightening, but truth is they are natural part of programming.

In fact, season developers just expect their code has mistakes or bugs, and they will spend as much time if not more time fixing those bugs. Debugging code is not something that you do only when needed, it is a necessary and expected part of the programming process.

Categories of Errors

In programming, there are two general categories of errors: syntax errors and logic errors.

Syntax Errors

Syntax errors occur when the code has not be properly formatted. This can include a missing quote, a misspelled variable name or a misplaced semicolon, but regardless the cause, the computer does not understand how to proceed.

While syntax errors can be common for new developers, they will generally make fewer of these mistakes as they get more experienced. Syntax errors are also relatively easy to fix, thanks to some helpful development tools like text highlighting, linters, and the JavaScript console.

We will learn more about how to use these tools later in the course.

Logic Errors

Logic errors occur when the code does not perform the way the developer had intended. This can include looping too few times or performing a set of tasks in the wrong order. Logic errors are often the main problem in a program and can be difficult to find and fix.