Friday, March 27, 2015

JavaScript console object

Many of us have used the JavaScript console object for logging
console.log("some debug message");
But for a lot of us, that's the extent. Maybe we use console.info or console.error, but there is so much more to the console. For example,
console.group
lets you nest statements in a group. The following snippet:
console.log('hello, I am outside the group');
console.group();
console.log('I am in the group');
console.log('me too');
console.groupEnd();
console.log('I am also outside the group');
Produces an output of
hello, I am outside the group
    I am in the group
    me too
I am also outside the group
While the console should only be used for debugging (and there are better libraries for just printouts like debug) and is not necessarily standard across browsers, it can be a really powerful tool. Check out the console docs at https://developer.mozilla.org/en-US/docs/Web/API/Console for a full list of functions.