The void
operator evaluates the given expression and then returns undefined
.
(void
运算符计算给定的表达式,然后返回undefined
。)
The void
operator is often used merely to obtain the undefined
primitive value, usually using “ void(0)
” (which is equivalent to “ void 0
”).
(void
运算符通常仅用于获取undefined
原始值,通常使用“ void(0)
”(等效于“ void 0
”)。)
In these cases, the global variable undefined
can be used instead (assuming it has not been assigned to a non-default value).(在这些情况下,可以改用undefined
全局变量(假设尚未将其分配给非默认值)。)
An explanation is provided here: void
operator .
(这里提供了一个解释: void
operator 。)
The reason you'd want to do this with the href
of a link is that normally, a javascript:
URL will redirect the browser to a plain text version of the result of evaluating that JavaScript.
(您之所以要使用链接的href
这样做是因为,通常,一个javascript:
URL会将浏览器重定向到评估该JavaScript的纯文本版本。)
But if the result is undefined
, then the browser stays on the same page.(但是,如果结果undefined
,则浏览器将停留在同一页面上。)
void(0)
is just a short and simple script that evaluates to undefined
.(void(0)
只是一个简短的脚本,其结果为undefined
。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…