Block (programming): Difference between revisions

Content deleted Content added
simplify, reduced editorializing
Loop-invariant code motion is a compiler optimization, not part of the language semantics; define hoisting more clearly
Line 140:
 
==Hoisting==
In some languages, a variable can be declared at function scope even within enclosed blocks. For example, in Javascript, variables declared with <code>var</code> have function scope.
In a few circumstances, code in a block is evaluated as if the code were actually at the top of the block or outside the block. This is often colloquially known as ''hoisting'', and includes:
* [[Loop-invariant code motion]], a compiler optimization where code in the loop that is invariant is evaluated before the loop;
* [[Variable hoisting]], a scope rule in JavaScript, where variables have function scope, and behave as if they were declared (but not defined) at the top of a function.
 
==See also==