What is Debugging?
Programming is a complex process. Since it is done by human beings, errors often occur. Programming errors are called bugs and the process of tracking them down and correcting them is called debugging.
Some claim that in 1947, a dead moth caused a problem in one of the first computers. The term “bug” has remained in use since, to refer to any issue that prevents a program from working as intended. National Geographic even has an image of the supposed first bug .
Three kinds of errors can occur in a program: syntax errors, runtime errors, and logic errors. We will first learn about each type of error, and then we will discuss strategies for debugging code and reducing errors.
Beginning Tips for Debugging
Debugging a program requires a different approach compared to writing the original code. As you debug, think of yourself as a detective. Something has gone wrong, and you must use clues, experience, intuition, trial and error, and an inquisitive spirit to solve the problem.
In this chapter, we will discuss in detail common types of bugs, along with some effective strategies for debugging. You will learn to rely on error messages and
console.log for clues and insight, and over time you will sharpen your debugging skills. We will also discuss how to approach writing code so as to prevent bugs from occurring in the first place.