When you add a property to an object, you can make it custom or non-configurable. An example of the long side of your example:
x = 42;
there is
Object.defineProperty(window, 'x', {
value: 42,
writable: true,
configurable: true,
enumerable: true
});
Custom properties can be deleted, which removes them from the object (this can lead to memory recovery, but it is not direct).
You can also write:
window.x = 42;
This makes it more obvious when we move on to the next problem.
window.x = 42;
var y = 43;
, y. . delete .
y - , , , ( 0 ).
:
Object.defineProperty(window, 'x', {
value: 42,
writable: true,
configurable: false,
enumerable: true
});
false , .