The intent of my question is to determine which of these two meanings is correct Some use it as a synonym for "global property", while others define it to mean a global property which has been defined via a var statement. However, the term "global variable" appears to be ambiguous. I do understand the term "global property" - a global property is a property of the global object. So, which interpretation is correct? Do both terms represent the same set of bindings, or is one a subset of the other?
Only statically scoped global properties are global variables
Now, based on this new information, one could say that only statically scoped global bindings may be referred to as both global properties and global variables, whereas dynamically added global bindings are merely global properties, but not global variables, meaning that the term "global variable" represents a subset of the set represented by the term "global property", as in:Īll global variables are global properties That being said, it should be noted that it is possible to create non-configurable global properties: fineProperty( this, 'bar', ) // non-configurable by default the binding "foo" cannot be removed subsequently the binding "bar" can be removed from the global environment subsequently the names "foo" and "bar" are bound to the global environment they cannot be deleted (more specifically, their corresponding bindings cannot be removed from the environment subsequently), whereas global properties created through assignment are configurable. Global variables are non-configurable, i.e. So, global variables are bound before program evaluation, whereas global properties are bound during program evaluation, when the assignment is evaluated. Global variables are statically scoped, whereas global properties are dynamically added to the global environment: foo // => undefined var foo = 1, and a global property created through an assignment, e.g. However, there are two differences between a global variable created using var ,e.g. Now, based on the above information, it would seem that it would be appropriate to use the terms "global variable" an "global property" interchangeably, meaning that both terms represent the exact same set of global bindings. This.foo // accessing the global variable via a property reference Var foo = 1 // creating a global variable
#Another word for variable terms code#
This also means that global variables may be accessed via property references: // global code This.foo = 1 // creating a global propertyįoo // accessing the global property via a direct reference This means that global properties may be accessed via direct references (like variables): // global code The global object serves as the top-level lexical environment (the top of the scope-chain, if you will).