1

I'm sorry if this question has been asked several times and in much clearer terms, but I just don't know the technical term for what I'm looking for. I'm trying to write a conditional statement in the following way:

if (data && data.password && data.password.length > 7) {// Do something}

But I know there is a simpler way to write this. Something like

if (data?password?length > 7) {// Do something}

What would be the correct formulation? What is the technical term for this type of expressions?

Andy
  • 61,948
  • 13
  • 68
  • 95
David
  • 41
  • 1
  • 8

1 Answers1

3

Concept you are looking for is called Optional Chaining

You can modify to : data?.password?.length

Sagar
  • 1,374
  • 10
  • 18