What does ?. mean in angular 5?

  • A+
Category:Languages

I know the if I have something like product.id == 1 ? stuff : not stuff. That means if id = 1, then choose "stuff". If not, then choose "not stuff". What does the following mean:

product?.id.name 

 


Literally this means:

((product == null) ? null: product.id.name) 

So if product is null then return null otherwise return the whole value.

What does ?. mean in angular 5?

If we have:

product?.id?.name 

then we should expect something like:

((product == null) ? null: ((product.id == null) ? null: product.id.name)) 

If you're doubt then you can always check how it looks like after angular compiler:

For more details see docs:

Comment

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