I had similar question and best answer is that MSIE doesn't have console
object until F12 tools have been open. So javascript throws error. Once you open developer tools, console
exists and console.log()
doesn't throw.
I use this code to maintain compatibility during development:
try {
if (typeof console == "undefined") {
this.console = {
log: function () {} //warn, error, ...
};
}
} catch (e) {
this.console = {
log: function () {} //warn, error, ...
};
}
However, it is recommended to remove all console references from production code.
EDIT: Changed window
into this
to access global scope as it pleases MSIE more.