Will console.log reduce JavaScript execution performance?

前端 未结 9 1260
半阙折子戏
半阙折子戏 2020-12-24 00:03

Will use of the debugging feature console.log reduce JavaScript execution performance? Will it affect the speed of script execution in production environments?

9条回答
  •  心在旅途
    2020-12-24 00:37

    If you create a shortcut to the console in a common core script, eg:

    var con = console;
    

    and then use con.log("message") or con.error("error message") throughout your code, on production you can simply rewire con in the core location to:

    var con = {
        log: function() {},
        error: function() {},
        debug: function() {}
    }
    

提交回复
热议问题