I have a class with an optional field startDateHour
:
export class Test {
startDateHour?: number;
// more fields, constructor etc.
}
I want to do something, if startDateHour
exists:
if (test.startDateHour) {
//do something
}
The problem is that this check doesnt work as expected when startDateHour
is 0. If its 0 it still exists and i want to execute the code, but if (startDateHour)
returns false in that case.
Of course i could do something like:
if (test.startDateHour || test.startDateHour === 0) {
// do something
}
But is there a better way, like one check which does both the things above?