Debugging in the JavaScript console has a lot more power than simply console.log
.
Here are some examples of available debugging methods when writing JavaScript, as well as examples
on how to debug in the console yourself.
Some tips on useful usage:
- Always assume someone else will view your development code (open-source).
- Always display your errors/warnings appropriately to assist in meaningful feedback.
- Add as much relevant information to the error message as possible to eliminate searching up the stack (like inlining the failed object).
- Console frequently in development. There's never "too much" information. If you have a log, group the logging for easier browsing.
Responding to an error from a third-party library should be fairly simple to understand. Most third-party libraries will have good debugging in them already (if they follow the above rules), so make sure to pick libraries that do.
Helpful tips:
- If something isn't working as you would expect, always check the console first.
- If there is nothing in the console, look at the specific piece of code that should be outputting the UI or data.
- Console relevant data that should be accurate to verify it's not undefined or otherwise (see below).
- If everything checks out, work your way up the call stack in your application, verifying each piece of data.