Closed
Bug 676015
Opened 15 years ago
Closed 15 years ago
Doc error: non-existing variable is described as "undefined" - should be "does not exist"
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: MartinRinehart, Unassigned)
Details
User Agent: Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0
Build ID: 20110615151330
Steps to reproduce:
Used a variable name in JavaScript. The variable did not exist.
Actual results:
Got a ReferenceError. (That's correct.) Accompanying text said the var was "undefined" (that's not correct).
Expected results:
A var name that is not the name of a var should be described as "does not exist" or similar. The term "undefined" should apply to a JavaScript undefined value or type.
Please notify when fixed. It's now in a book I'm writing. Going to press in the fall.
undefined is the value the variable contains until its been given a value, and it is according to the ECMAScript specs[1]:
4.3.9
undefined value
primitive value used when a variable has not been assigned a value
8.1
The Undefined Type
The Undefined type has exactly one value, called undefined. Any variable that has not been assigned a value has the value undefined.
So I'm going to mark this invalid as it follows the spec.
[1] http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
Status: UNCONFIRMED → RESOLVED
Closed: 15 years ago
Resolution: --- → INVALID
| Reporter | ||
Comment 2•15 years ago
|
||
My dear Cork, please read again. What you say is correct, but not to the point. A declared name is part of a name/value pair and its value, until assigned otherwise, is "undefined" per the specs.
However, this is not applicable to names that have not been created. A non-existing name simply does not exist and it does not have a value. Attempting to reference a non-existing name is, Ff correctly shows, a ReferenceError. (Another browser calls it a TypeError, which is dead wrong: no type === not TypeError.) It is not the case that non-existing names, ReferenceError names, have values. Values are assigned to names.
These are the cases, per the spec:
case 1:
alert( x ); // (assume there is no 'x') ReferenceError, script terminated
-----------------------------
case 2:
var x; // undefined value assigned, script continues
alert( x ); // alerts 'undefined', script continues, not an error
Updated•15 years ago
|
Assignee: nobody → general
Component: General → JavaScript Engine
Product: Firefox → Core
QA Contact: general → general
You need to log in
before you can comment on or make changes to this bug.
Description
•