Get 'undefined' if 'window.undefined' is overwritten

前端 未结 4 1053
萌比男神i
萌比男神i 2020-12-30 08:46

It appears that window.undefined is writable, i.e. it can be set to something else than its default value (which is, unsurprisingly, undefined).

4条回答
  •  滥情空心
    2020-12-30 09:01

    In addition to the other solutions, you can do the void 0 trick, which always returns undefined irrespective of the window property.

    window.undefined = 'foo';
    var blah = void 0;
    
    alert( blah );  // undefined
    

提交回复
热议问题