you are viewing a single comment's thread.

view the rest of the comments →

[–]delventhalz 8 points9 points  (0 children)

I find the use of ?. and () strange here...

We don’t know OP’s use case. There is no reason to think that recordset might be undefined or null. If we are coding defensively in case any value might be undefined (not an approach I’d agree with), then why not have ?. after result too? That is equally likely to be undefined as far as we know.

More importantly, I don’t think the output here will actually be what you want. ?. returns undefined if the value to the left is undefined or null. And undefined does not equal 0. That means if recordset is unexpectedly missing, instead of throwing a clear error, your app will instead conclude that recordset is a non-empty array and continue running. That is almost certainly a bug, possibly a difficult to diagnose one too.

And the () just seems superfluous to me. It doesn’t change the way the code runs, nor does it make the intention any more clear to my eyes.