What
void: prefix operator
void 0 will return undefined as well
Why
Why using void 0 alternative to undefined?
Because undefined is a global variable:
In early, you can change the undefined directlty
console.log(undefined) // Output: "undefined"
var undefined = "I am new value"
console.log(undefined) // Output: "I am new value"
Now, the undefined is set read-only, but you still change it in local scope
{
const undefined = "I am new value"
console.log(undefined) // Output: "I am new value"
}
It will be significant that avoiding certain exception by using void 0.
Meanwhile, another trivial advantage is void will occupies less byte compared with undefined.
Summary
- Avoid exception since
undefinedis a global variable can be changed arbitrarily under some conditions. - occupy less byte
Reference
https://stackoverflow.com/questions/7452341/what-does-void-0-mean

813

被折叠的 条评论
为什么被折叠?



