因为undefined在javascript中不是保留字,所以可能有变量被无意命名为undefined:
undefined
javascript
123456
function test() { var undefined = "Hello world!"; console.log(undefined === void 0); // false}console.log(undefined === void 0); // truetest();
所以我们会用void 0来获取undefined
void 0
123
_.isUndefined = function(obj) { return obj === void 0;}
确保<a/>点击时不会产生页面跳转;确保<img/>不会向服务器发出垃圾请求.
<a/>
<img/>
12
<a href="javascript:void(0)"></a><img src="javascript:void(0)"></img>