This will throw if console is not defined. Try
if (!window.console)
Or if (typeof console == 'undefined')
Or if !('console' in window))
N