Search code examples
javascriptecmascript-5

What is the obj?.prop syntax in javascript?


I was looking through a code and I came across this:

{{abc?.xvy=== tyu?abc?.xz:abc?.xz}}

I am unable to understand meaning of this expression. I know that it is Null-safe property access but I am bit confused about the chaining. Any help is much appreciated


Solution

  • Its new ES proposal called "optionals" for safe check reading for object properties. Above expression is equivalent to:

    (abc && abc.xvy) === (tyu) ? (abc && abc.xz) : (abc && abc.xz)
    

    You can find more details here: https://github.com/davidyaha/ecmascript-optionals-proposal