I\'m using Firebug and have some statements like:
console.log(\"...\");
in my page. In IE8 (probably earlier versions too) I get script err
You can use the below to give an extra degree of insurance that you've got all bases covered. Using typeof
first will avoid any undefined
errors. Using ===
will also ensure that the name of the type is actually the string "undefined". Finally, you'll want to add a parameter to the function signature (I chose logMsg
arbitrarily) to ensure consistency, since you do pass whatever you want printed to the console to the log function. This also keep you intellisense accurate and avoids any warnings/errors in your JS aware IDE.
if(!window.console || typeof console === "undefined") {
var console = { log: function (logMsg) { } };
}