Wednesday 1 June 2016

Error console is undefined ie 8 [solved]

What the hack gone with deployed JavaScript running code, forgotten to comment  and got the same error "console is undefined".
console.log("hello");

Then i found console works only on IE8 if Developer tools is open.

Solution:
So what we could do here are:-
A. We can simply comment the console.log line. or

B. We could check console is open or not by using following line of code
if (console && console.log) {
    console.log('hello');
}

C. We can check console is undefined or not.
if(typeof console === "undefined") {
    console = {
        log : function () {}
    }
}