Pass arguments to console.log as first class arguments via proxy function

This should do it ..

function log() {
    if(typeof(console) !== 'undefined') {
        console.log.apply(console, arguments);
    }
}

Just adding another option (using the spread operator and the rest parameters – although arguments could be used directly with the spread)

function log(...args) {
    if(typeof(console) !== 'undefined') {
        console.log(...args);
    }
}

Leave a Comment