Bad idea to leave “console.log()” calls in your production JavaScript code?

后端 未结 11 2032
醉话见心
醉话见心 2020-12-07 08:03

I have a bunch of console.log() calls in my JavaScript.

Should I comment them out before I deploy to production?

I\'d like to just leave them th

11条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-07 08:23

    You should at least create a dummy console.log if the object doesn't exist so your code won't throw errors on users' machines without firebug installed.

    Another possibility would be to trigger logging only in 'debug mode', ie if a certain flag is set:

    if(_debug) console.log('foo');
    _debug && console.log('foo');
    

提交回复
热议问题