When you write:
window.dog = 1;
you are explicitly creating a new property on the global window
object called dog
. As such, when it gets created, it gets created with its configurable
switch set to true
. The fact that you then declare
var dog = 6;
doesn't change the fact that the property has already been explicitly created.
When you declare:
var cat = 9;
you are implicitly creating a property called cat
on the global window
object. Created this way, the property has its configurable
switch set to false
.
The point being that global properties are generally a bad thing and in the rare occasions when you might want one, it is best to be explicit about it, for readability sake, but also (as you have found out) for the most flexibility in working with them.