4.1.4 Detection Type
Although TypeOf is the right hand when detecting a base data type, we do not want to know if a value is an object while detecting the value of a reference type, but want to know what type of object it is. The instanceof operator is provided for this ECMAScript:
Result=variable Instanceof Constructor
Ex:alert (Person instanceof object), alert (colors instanceof Array), alert (pattern instanceof REGEXP);
The value of all reference types is specified as an object instance.
typeof regular (different browsers will return function or object). ECMA-262 specifies that any object that implements the [call] method internally should return "function" when the typeof operation is applied.
4.2 Execution Environment and scope
The execution Environment (execution context) defines the other data that variables and functions have access to, determines their behavior, and each execution environment has a variable object associated with it (variable object), and all variables and functions defined in the environment are stored in the object. Although the code we write does not have access to this object, the parser uses it in the background when it processes the data. The global execution environment is one of the outermost execution environments. Depending on the hosting environment where the ECMAScript implementation resides, the objects that represent the execution environment are different. In a Web browser, the global execution environment is considered a Window object, so all global variables and functions are created as properties and methods of the Window object, and the code in an execution environment is executed, the environment is destroyed, All variables and function definitions stored therein are also destroyed (the global execution environment is not destroyed until the application exits).
JavaScript advanced Programming--Chapter 4th: variables, scopes, and memory issues