In some older browsers, including versions of Internet Explorer, window.console doesn’t exist and therefore calling console.log() will result in an error.

One way of fixing this is to create a function which checks whether console exists and use this function instead:

function consolelog(v){
    if (window.console
        && window.console.log){

However this requires all developers knowing about this function, and if someone forgets and directly calls console.log() then older browsers will still throw an error.

Therefore a better solution is to check whether console.log() exists, and if not, create an empty function which prevents the error occurring.

if (!(window.console
    && window.console.log)){
    window.console = {

Alternatively a better shorthand method would be:

window.console = window.console || {log:function(a){}};