Pacman IE, CC-0 by Hoper Lyle Celtic

How to prevent IE from messing with console.log

Short answer

  1. Add the following before any use of console.log:

    Or (which is OK with JSHint’s undef rule):

    Or make a log function that will not add a potentially useless object and that you will use instead of console.log:

    (or just make sure you do not use console.log)

Something more detailed

I ran once in a bug when JavaScript would run perfectly in all browsers save Internet Explorer. I started IE’s debug tool and then everything was fine and finally found a call to console.log which I had forgotten from a debug session.

I deduced that, to save time, IE do not instantiate a console object unless the debug tool is up. That means if you need to log, you have either to make sure the object and function are present, either by creating it yourself or testing it every time.

Of course, the ideal solution would be not to use console.log at all but we have to admit it is a nice shortcut when debugging.

Published by

Cyrille Chopelet

Programming addict, UX philosopher, casual gamer, sci-fi enthusiast, hi-tech dilettante, ... Some people even call me a geek.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.