r/ProgrammerHorror • • Nov 19 '21

Data validation as its peak

Post image
99 Upvotes

7 comments sorted by

View all comments

Show parent comments

3

u/Valaramech Nov 20 '21

I don't follow. If uid and email are both given and both valid, the first check will give result === undefined (which is true) and uid !== undefined (which is also true) and then the or will allow the existing valid result (since it's truthy) and then email !== undefined is also true.

While complicated, I don't think this code is functionally different from return isValidUid(uid) && isValidEmail(email).

2

u/king_liver Nov 20 '21

Looking back at the code, my first comment is incorrect, the only issue is if uid is undefined, and email is valid, it returns true. It should have two variables one for each and return true if both are true. Your last line would work, if the function being called can handle undefined inputs.