What is the obj?.prop syntax in javascript?

  • A+

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


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


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: