As much as I hope that things will always work from first try, better to be prepared to debug it. console.log remains the main tool to do it, because it is the simplest and fastest.
Few console methods are known to everybody, log, warn and error.
There are more tricks to it.
For example, if you need to count how many times component re-render can use console.count, e.g. console.count('comp1')
Can log some info in a collapsed group with console.groupCollapsed, great in case of many error messages, when they printed collapsed it's less distracting, but Node.js/Sentry probably will print all expanded.
After click
Can use some CSS
Can log properties of an object with console.dir
Can log few objects with curly braces like console.log({ obj1, obj2 }), instead of console.log('Ojb1', obj1)
Can assert things with console.assert
Can measure how long some operation takes with console.time
Print a stack trace with console.trace()
Clear things up with console.clear()
Check out great old post - https://dev.to/lissy93/fun-with-consolelog-3i59
The above is the detailed content of Beyond console.log. For more information, please follow other related articles on the PHP Chinese website!