Open Bug 1394123 Opened 2 years ago

Property Accessors: No mention of what happens when a property is not present on an object

Categories

(Developer Documentation :: JavaScript, defect, P5)

All
Other
defect

Tracking

(Not tracked)

UNCONFIRMED

People

(Reporter: jason, Unassigned)

References

()

Details

:: Developer Documentation Request

      Request Type: Correction
     Gecko Version: Trunk
 Technical Contact: 

:: Details

Property Accessors documentation (Javascript ref, operators) explains the use of dot notation and bracket notation for accessing properties of an object, but does not explain what occurs when no such property exists on the object.  Consider:

    var myObj = {foo: 1}

What does `myObj.bar` return?  What about `myObj['bar']`, any difference?  I *think* both return `undefined` (not certain, that's why I'm checking the docs), but someone coming from another language could expect `null` to be returned, or even an exception to be thrown.  Also, is there any mechanism available to intercept attempts to access such undefined properties, and act on them?
You need to log in before you can comment on or make changes to this bug.