Chrome’s Console API: Greatest Hits
mitchrobb.com
mitchrobb.com
console.log(JSON.stringify(someObject, null, 2))
Will nicely indent it for you.1. in IE 8, it will choke. it needs to be a function (hopefully you don't have to care about IE 8, though)
2. in all other JSON.strigifable browsers, you can skip it with a falsey value, which is what the `null` is doing here. As a result, you can also use `0` (e.g. stringinfy(foo, 0, 2)), which I like because I can type it faster
In IE the 'console' object doesn't even exist if the developer tools aren't displayed, so if you use "console.log" in your program, your js will just throw an NPE.
Note that if you try closing the Developer Tools, 'console' is still declared for this page and all descendant pages. To test 'console.log' you need to avoid opening the devtools and open a new tabs.
A linter will catch this.
Note though it's not `console.copy` but `copy`; it's a part of Command Line API [1] which is not the same as Console API [2] - command line API is not accessible from JS of the page.
[1] https://developer.chrome.com/devtools/docs/commandline-api#c...
* console.watch & console.unwatch
* console.timeline & console.timelineEnd
* console.timeStamp, console.time, console.timeEnd
* console.markTimeline
* console.groupCollapsed
* console.exception
In Firefox Nightly. A few of the timeline ones don't seem to work just yet, as the timeline is currently being prototyped in Nightly.
watch/unwatch are from Object.prototype, confusingly enough!
Another pet peeve of mine: at the moment, only in firebug I can call console.log() passing a function, get a nice, clickable function definition, that can get me directly to the "debugger" section, at the right place where the function is.