STAGING not indexed production at recoveryarea.nl

javascript · · 1 min read

A smarter console.info

A tiny defensive wrapper that picks console.dir for objects and arrays and console.info for primitives — back when Firebug and Chrome disagreed about logging.

Console output showing the wrapper handling a string with console.info and an object expanded with console.dir

Here is a little piece of code you can use in your project for slightly smarter console messages. Objects and arrays are handled differently when logged to the console than strings. Firebug gives you a stringified version of the object while console.dir gives you an expandable object. Both give you the expandable object in Chrome. To work around this you can use this little snippet, it will always give you the correct version.

var debug = function(message) {
	"object" === typeof console && ("object" === typeof message || "array" === typeof message ? console.dir(message) : console.info(message));
};