84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
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
光阴似箭催人老,日月如移越少年。
Because the variable declared withvarhas the attributeconfigurable = false, so it cannot be deleted.
var
configurable = false
var ss = 0; console.log(Object.getOwnPropertyDescriptor(window, 'ss')); /* { configurable: false enumerable: true value: 0 writable: true } */
Because the variable declared with
var
has the attributeconfigurable = false
, so it cannot be deleted.