Debugging objects in Internet Explorer

Have you ever tried to log your Object in Internet Explorer (IE)? Even a half decent one with a built in console?

Yep, you just get the helpful “LOG: [object Object]”… *sigh*

Well, don’t panic, there is a really quick cheat to serialize the object as a JSON string and log that instead:

var obj = {foo:'bar'}
//logs {"foo":"bar"}

…also, you can pass any value to this function, it doesn’t have to be an object.