I should let it be known just because, and I’ll go through this stage to clean the skeletons from my advancement storage room. Now and then, the enchantment I do — which some call “coding” — isn’t as impeccable as the result may appear to my partners when the brilliant outcomes are appeared to them. Truly, I said it – here and there, I utilize the old experimentation we as a whole call troubleshooting 🙂
Indeed, we as a whole know its essentials:
console.log(‘Hello World!’);/log a message or an item to comfort
console.info(‘Something occurred… ‘);/same as support log
console.warn(‘Something unusual occurred… ‘);/same as support log yet yields an admonition
console.error(‘Something frightful occurred… ‘);/same as comfort log however yields a blunder
So ideally now, I can give you a few hints which you didn’t know previously, and which will make you a PRO debugger.
Tip #1 console.trace()
On the off chance that you need to know where the log is being incited from use console.trace() to get the stack follow with the logged information.
Tip #2 console.time() && console.timeEnd()
On the off chance that you are attempting to locate a subtle exhibition issue, start tallying time with console.time() and print with console.timeEnd().
Tip #3 console.memory
On the off chance that your exhibition issue is significantly trickier, and you are searching for a slippery memory spill, you may get a kick out of the chance to attempt to use console.memory (property, not a capacity) to look at your store size status.
Tip #4 console.profile(‘profileName’) and console.profileEnd(‘profileName’)
This isn’t standard, however is broadly upheld. You can begin and end a program execution device – execution profile from the code utilizing console.profile(‘profileName’) and afterward console.profileEnd(‘profileName’). This will assist you with profiling EXACTLY what you need, and keeps you from being mouse-click, timing subordinate.
Tip #5 console.count(“STUFF I COUNT”)
For a situation of repeating capacity or code, you can utilize console.count(‘?’) to keep tally of how frequently your code is perused.
Tip #6 console.assert(false, “Log me!”)
Truly, restrictive logging without wrapping your logs with if-else 🙂
You can utilize console.assert(condition, msg) to log something when the condition is falsy.
*disclaimer — in Node.js this will toss Assertion Error!
Tip #7 console.group(‘group’) and console.groupEnd(‘group’)
In the wake of composing such a significant number of logs, you should arrange them. A little and helpful device for that is the console.group() and console.groupEnd(). Utilizing console gathering, your comfort logs are assembled, while each gathering makes another level in the order. Calling groupEnd diminishes one.
Tip #8 String substitutions
When logging, you can consolidate factors utilizing string substitutions. These references ought to be types (%s = string, %i = number, %o = object, %f = drift).
Tip #9 console.clear()
All things considered, having composed such a large number of logs, it’s currently time to clear your support a bit.
Tip #10 console.table()
Holding back something special for later, this is a genuine jewel as I would see it! You can really print an exceptionally decent table with the articles you log utilizing the console.table()
I truly trust these tips make your troubleshooting more gainful, and even somewhat fun!