I have this problem when a variable is missing a field and the user receives a warning that this or the same variable does not have this or that property. In the simple case, this is very straightforward.
if(field) doSomething(field.subField);
However, in empirical situations, I found myself getting to this absurd bust.
if(!data || !data.records || !data.records[0] || !data.records[0].field || !data.records[0].field.id) return null; doSomething(data);
I mean, c'mon is like a pipe if I'm a plumber, not a developer. Thus, I have a very strong feeling that my checks, although sufficient, may be a little too much - too crowded. Is there an agreement in JS about when to validate?
user1675891
source share