You do not know the JS series (4) - Scope discrimination abnormal

In the variable has not been declared, the behavior of LHS, RHS both queries is not the same

 

function foo(a){
  console.log(a+b);
  b=a;
}
foo(2);

 

The first time to be b RHS inquiry is not looking to play the variables, if not anywhere to be found in the RHS query all the necessary nested scopes variables, the engine will throw an exception ReferenceError

 

When the engine executes the query LHS, if can not find the target variable in the global scope, global scope will create a variable with that name

 

If you find a query RHS variable, but try to be reasonable for this variable operation, such as trying on a non-function type of value the function call, or a reference to null or undefined type value of property, then the engine will throw TypeError abnormal.

 

Summary: ReferenceError failure associated with determining the scope of, and determine the scope TypeError represents a success, but the results of operations are illegal or unreasonable

 

Guess you like

Origin www.cnblogs.com/wzndkj/p/12306470.html