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
- window.console will check if this console function exists or not.
- 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