Grant Wagner said:
function abc() { alert('hi'); }
function abc() { alert('bye'); }
abc();
is equivilent to
var abc = new Function("alert('hi');");
var abc = new Function("alert('bye');");
abc();
While the conclusion is correct, this statement is slightly incorrect.
(I.e., ignore this unless you are a pedant like me
When Javascript interprets a block of code, it first treats all the
function declarations in the order they appear, i.e., it creates the
local variable and assigns their value. Then it treats all the
variable declarations and declares the variables (i.e., creates them
as properties of the variables object if they don't exist already),
but does not assign a new value, even if the declaration looks like
"var foo=42;". That is treated like "var foo;foo = 42;".
Then it executes the code, including the assignments to variables.
So
var foo = 42;
function foo(){}
alert(foo);
will alert "42".
In any case, declaring a function or variable will create it as a
local variable, a property of the variable object of the
scope. Creating it twice is allowed, and the last assignment to it
will win (functions first, in the order they appear, then assignments
in the normal code, in the order the are executed).
/L