javascript - Variable delete declared through var cannot be deleted, but it is also a property of window?
大家讲道理
大家讲道理 2017-06-14 10:52:39
0
1
662

The variable delete declared through var cannot be deleted, but it is also a property of window? Seek to explain

var foo = 1; window.bar = 2; delete foo; delete bar; console.log(window.foo,window.bar)//1 undefined
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all (1)
过去多啦不再A梦

Because the variable declared withvarhas the attributeconfigurable = false, so it cannot be deleted.

var ss = 0; console.log(Object.getOwnPropertyDescriptor(window, 'ss')); /* { configurable: false enumerable: true value: 0 writable: true } */
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!