I recently got through the Debugging set of lessons on FreeCodeCamp. Here are a few points I learned.
There are 3 types of errors:
- Syntax – misspelled word, missing parentheses, etc.
- Runtime – detected while running the program.
- Semantic – detected after testing output. Program works but result is wrong. Be careful!
1. Use DevTools on Chrome or Firefox
console.log(); a lot.
console.log spits out the value of whatever is in the
() to the browser console, which helps you keep tabs on how a value is changing in your code. Sometimes you have to move the
console.log to a different place, like before or after another function, because order matters and the value of your value can change.
Use console.clear(); to clear the memory of a value in the console. Sometimes it’s ok to forget.
typeof to keep track of values. For instance sometimes a number is a numeral and sometimes it’s a string. Write
console.log(typeof value); and that will tell you the type for value.
5. Lastly, you have to watch out for misspellings, missing brackets or parentheses, using ‘=‘ instead of ‘==‘, or getting the dreaded infinite loop.
Next in FreeCodeCamp is Data Structures!