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
  • 53,323
  • 11
  • 64
  • 89
David
  • 31
  • 6

1 Answers1

3

Concept you are looking for is called Optional Chaining

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

Sagar
  • 1,230
  • 8
  • 16