JavaScript: How do I print a message to the error console?

console.error(message); // Outputs an error message to the Web Console
console.log(message); // Outputs a message to the Web Console
console.warn(message); // Outputs a warning message to the Web Console
console.info(message); // Outputs an informational message to the Web Console. In some browsers it shows a small "i" in front of the message.

You also can add CSS:

console.log('%c My message here', "background: blue; color: white; padding-left:10px;");

More info can be found here: https://developer.mozilla.org/en-US/docs/Web/API/console


Exceptions are logged into the JavaScript console. You can use that if you want to keep Firebug disabled.

function log(msg) {
    setTimeout(function() {
        throw new Error(msg);
    }, 0);
}

Usage:

log('Hello World');
log('another message');

Install Firebug and then you can use console.log(...) and console.debug(...), etc. (see the documentation for more).


One good way to do this that works cross-browser is outlined in Debugging JavaScript: Throw Away Your Alerts!.