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?

3

1 Answer 1

3

Concept you are looking for is called Optional Chaining

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.