Closed
Bug 257648
Opened 21 years ago
Closed 21 years ago
"redeclaration of var" is wrong
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: bugzilla, Unassigned)
Details
I'm getting:
--------------
Warning: redeclaration of var x
Source File: file:///c:/temp/test.html
Line: 4, Column: 5
Source Code:
var x;
--------------
my code:
<script>
var x=1;
if (typeof(x)=="undefined") {
var x;
}
x=2;
</script>
Mozilla Firefox 20040830
Comment 1•21 years ago
|
||
Aren't the declarations handled at compile time, not runtime (due to the fact
that they have function scope and don't need to come before use)? For example,
"x" is declared in the following JS and there should be no "assignment to
undeclared variable" warning:
function foo() {
x = 1;
if (0) {
var x;
}
}
Your testcase is pretty much the same and does indeed declare the variable twice.
Comment 2•21 years ago
|
||
Variable declarations are hoisted to the top of their execution scope (in JS1
that's most enclosing function, or global if none).
Comment 3•21 years ago
|
||
Per comment 2, invalid.
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•