Stubbing console for older versions of Internet Explorer

Published: {ts '2015-03-31 00:00:00'}
Author: Steven Neiland
Site Url: http://www.neiland.net/article/stubbing-console-for-older-versions-of-internet-explorer/

As much as we wish it would go away and die quietly in a corner, sometimes you still have to provide at least minimal support for older versions of Internet Explorer.

One of the problems with older IE is that it did not support console functions such as log and group. This would have the nasty consequence of causing your javascript to break if you forgot to take out any of these debugging functions from your code.

To guard against this I include this code snippet in my javascript utility scripts.

if( typeof console == "undefined" ){ console = { log: function() {}, group: function () {}, error: function () {}, warn: function () {}, groupEnd: function () {} }; }