en.javascript.info icon indicating copy to clipboard operation
en.javascript.info copied to clipboard

optional chaining: error in summary?

Open Palaing opened this issue 4 years ago • 0 comments

The Summary section of page https://javascript.info/optional-chaining reads:

  1. obj?.prop – returns obj.prop if obj exists, otherwise undefined.
    
  2. obj?.[prop] – returns obj[prop] if obj exists, otherwise undefined.
    
  3. obj.method?.() – calls obj.method() if obj.method exists, otherwise returns undefined.
    

but it seems that the first 2 lines should rather say:

  1. ... obj.prop if obj.prop exists...
  2. ...obj[prop] if obj[prop] exists... => actually in both cases when obj does not exist, as explained before in the chapter, it will throw an error.

Palaing avatar Oct 26 '21 13:10 Palaing