0

I am using console.log to log all error messages.

console.log('foo');

it works in chrome and firefox, but in IE9, I am getting console is undefined. The fix for this is.

window.console && console.log('foo');

now, in IE9 it works, but I dont know why it works. my understanding is

  1. window.console will check if this console function exists or not.
  2. then if it does exist, we use console.log to log the message.

In IE9, I would expect window.console to fail, console.log('foo') should never be triggered.

why it works, why i can see the logged message in IE9 developer tool

qinking126
  • 11,385
  • 25
  • 74
  • 124
  • 2
    http://stackoverflow.com/questions/5472938/does-ie9-support-console-log-and-is-it-a-real-function – Can Feb 15 '13 at 14:32

1 Answers1

0

It will work only when the console is actually open.

James Montagne
  • 77,516
  • 14
  • 110
  • 130