en.javascript.info
en.javascript.info copied to clipboard
optional chaining: error in summary?
The Summary section of page https://javascript.info/optional-chaining reads:
-
obj?.prop – returns obj.prop if obj exists, otherwise undefined. -
obj?.[prop] – returns obj[prop] if obj exists, otherwise undefined. -
obj.method?.() – calls obj.method() if obj.method exists, otherwise returns undefined.
but it seems that the first 2 lines should rather say:
- ... obj.prop if obj.prop exists...
- ...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.