Much of time of developers spent on fixing problems. When it comes to fixes, one need to be good and fast at debugging. Debugging is part of programming.
In the era of IE, most of the programmer debug using alert. But now a day’s many methods and tools added into browsers. Especially with firebug and chrome dev tools, lots of methods have been introduced.
Various methods of console API: assert,clear,count,debug,dir,dirxml,error,group,groupCollapsed,groupEnd,info,log,profile,profileEnd,time,timeEnd,timeStamp,trace,warn
Dev tools support breakpoints similar to the editor for server side languages. It stops execution to breakpoint from where you can inspect code and trace. You can Step into, out and over from there. You can on/off breakpoints without refreshing page.
Unfortunately, this API is deprecated from most of the browsers. you can find polyfill.
Syntax: Object.observe(obj, callback[, acceptList])
Sometimes you want to debug on some function call and search result of function name search returns nothing may be because of minification or special chars. For such scenario debug method will help you.
When the specified function is called, the debugger is invoked and breaks inside the function on the Sources panel allowing to step through the code and debug it, similar to breakpoint at first line of that function. To turn this off, use undebug(function).
Similar to debug, This method will not break execution of code.
When the function specified is called, a message is logged to the console that indicates the function name along with the arguments that are passed to the function when it was called.User can turn it off using unmonitor(function) method.
When user needs to monitor browser event, this function is useful. When passed event on passed object called, it will log event object on console. You can specify a single event to monitor, an array of events, or one of the generic events “types” mapped to a predefined collection of events. To turn this event off , user unmonitorEvents(object[, events])
Syntax: monitorEvents(object[, events])
Well written quote from Brian Kernighan and Book “The Elements of Programming Style”:
Everyone knows that debugging is twice as hard as writing a program in the first place. So if you’re as clever as you can be when you write it, how will you ever debug it?
If you liked this, click the 💚 below so other people will see this here on Medium.