什么是0; 在javascript中表示

mdi*_*ici 1 javascript

查看grunt-strip插件以删除console.logs.我意识到它用0;.替换了console.log语句.请问0;有什么影响?

dee*_*see 6

它没有任何影响,没有.JS评估0并且没有任何结果.这个想法是删除console.*(用一个简单的替换)可能会破坏这样的代码:

if(condition)
    console.log('');

functionCall();
Run Code Online (Sandbox Code Playgroud)

将成为(重新格式化重点......)

if(condition)
    functionCall();
Run Code Online (Sandbox Code Playgroud)

所以它被虚拟语句所取代.

if(condition)
    0; // Does nothing

functionCall();
Run Code Online (Sandbox Code Playgroud)

此外,代码检查控制台是否存在将返回false,因为0是假的.

if(console) { // Not executed when replaced by if(0)
    // debugging action
}
Run Code Online (Sandbox Code Playgroud)