JavaScript `undefined` vs `void 0`

前端 未结 4 1162
一个人的身影
一个人的身影 2020-11-28 08:52

What exactly is the difference between undefined and void 0 ?

Which is preferred and why?

4条回答
  •  没有蜡笔的小新
    2020-11-28 09:48

    The difference is that some browsers allow you to overwrite the value of undefined. However, void anything always returns real undefined.

    undefined = 1;
    console.log(!!undefined); //true
    console.log(!!void 0); //false
    

提交回复
热议问题