Will console.log reduce JavaScript execution performance?

前端 未结 9 1251
半阙折子戏
半阙折子戏 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:28

    I do it this way to maintain original signature of console methods. In a common location, loaded before any other JS:

    var DEBUG = false; // or true 
    

    Then throughout code

    if (DEBUG) console.log("message", obj, "etc");
    if (DEBUG) console.warn("something is not right", obj, "etc");
    

提交回复
热议问题