An Interest In:
Web News this Week
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
- March 26, 2024
Javascript Logging Tips and Tricks
console.log
and debugger
are probably the most common examples of debugging front end applications. Though log
is the most common console
function, there are a few others that you can leverage in your application for more descriptive and useful logging. In this post I'm going to cover a few extra functions you may not know about in the console
object.
Styled Logging
In addition to console.log
, there are a few functions to make your logging more semantic. console.info
, console.warn
, and console.error
can apply some extra styles to your log statements and make your code a little bit more descriptive:
Assertions
If you need to conditionally log an error, console.assert
takes an expression and will log an error if the assertion is false.
Tables
If you're logging table data, instead of using console.log(data)
, consider using console.table(data)
. console.table
optionally accepts a second argument that lets you specify what columns you'd like displayed.
Custom Styles
Info, warn, and error are a nice way to add some canned styles to your logging statements, but if you're looking for a little more control, console.log
accepts a second argument that allows you to style your log statements using CSS:
If you'd like to learn more, the full MDN reference is a great resource.
Original Link: https://dev.to/headwayio/javascript-logging-tips-and-tricks-2h2c
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To