Two methods of variable lookup today come into contact with LHS (Left Hand Side) and RHS (Right Hand Side) where relevant knowledge learning JavaScript, the reason you want to find JavaScript variables, JavaScript would have to understand the principles of operation of the variable assignment :
Variable assignment to perform two actions,
1, the compiler will declare a variable in the current scope (if not stated before too).
2, the engine will look for the variables in scope at run time, if you can find him will be assigned.
First of all we need to know JavaScript programs are compiled by executing JavaScript engine to complete, then we must first know what engine and his friends compiler and scope is
1, Engine: responsible for compilation and execution process from start to finish the entire JavaScript program.
2, the compiler: one good friend engines, is responsible for parsing and code generation dirty work.
3. Scope: Another good friend of the engine, responsible for collecting and maintaining a series of queries by the identifier (variable) consisting of all declared and implemented a set of very strict rules that determine the code currently executing on these identifiers access.
------- "You do not know the volume of JavaScript"
In the second step compiler generates compiled code execution, when the engine performs it, to determine whether it would have been declared, the search process will be assisted by the scope by looking variables, but how to perform the lookup engine will affect Find the final result. The so-called LHS and RHS find, I am sure you can guess "L" and "R" represents the left and right side, specifically what's left and right of it? Operation is the assignment of the left and right, but the assignment is not just oh assignment operator.
In order to be able to complete the principle of understanding JavaScript, you need to start thinking like engine (and his friends), ask questions from their point of view, and from their perspective to answer these questions, we first look at an example:
// code section
function foo(a) {
console.log( a ); //2
}
foo( 2 );
Let's deal with the process of the above code imagine a conversation, this conversation might be something like the following.
Engine: I said scope, I need to foo be RHS reference. Have you seen it yet?Scope: Do not say, I really have seen the compiler that kid just declare it. It is a function for you.
Engine: Dude too terrific! Well, I performed it foo .
Engine: scope, there is a thing. I need a conduct LHS reference to this you seen it?
Scope: This is also seen it recently compiler reputation as foo parameter a form, take it.
Engine: kindness without saying thank you always so great. Now I want 2 assigned to A .
Engine: Dude, I'm sorry to disturb you again. I want to console conduct RHS references, have you seen it yet?
Scope: We two who and who ah, say what I do. I also have, Console is a built-in object. Give you.
Engine: Meme clatter. I have to see there is not a log (..) . Great, found, is a function.
Engine: Dude, help me find it for a the RHS reference to it? Although I remember it, but would like to confirm once.
Scope: Rest assured, this variable does not change before, away, do not mention it.
Engine: Awesome. I put a value, i.e. 2 , passing into the log (..) .
------- "You do not know the volume of JavaScript"
LHS and RHS is the meaning of "the left and right of the assignment" does not necessarily mean "= left or right side of the assignment operator. Assignment There are several other forms, it is best to conceptually understood as "who is the target of an assignment operator (LHS)" and "who is the source of an assignment (RHS)".
In the above example should be noted that: console.log (..) itself requires a reference to perform, so will the console RHS query object, and whether there is a method called log values obtained in the examination. I will not be here to log RHS query. After the completion of inquiries because of the console, the object attribute access rules will take over the access log attributes. In other words, if the property is access to the object does not exist query LHS and RHS query, can not find it returns undefined.