3 ms·
I'm not sure how it looks in ObjC but in Typescript you could write something like: let studentScoreFormatted: string = student.formattedScore ?? 'Student ha
by AgloeDreams 7y ago
I'm not sure how it looks in ObjC but in Typescript you could write something like:
let studentScoreFormatted: string = student.formattedScore ?? 'Student has not taken this test yet.';
Whereas if the score is null it will return the value after `??`.
It is awfully helpful for ensuring you handle error states in displaying API values. Additionally if you want this behavior but when the value is falsey, then you can use `||` instead.
- jamil7 7y agoDo you mean Swift? I didn't think Typescript had something like this yet.
- h0h0h0h0111 7y agoNot sure about OP, but this is coming in Typescript 3.7 I believe. Currently you can use `||`, but as mentioned above it will also catch false, 0, "", etc
- AgloeDreams 7y agoBingo. TS 3.7
- leshow 7y ago?? doesn't exist in typescript yet, but there is a tc39 proposal to add it to js proper
- AgloeDreams 7y agoTS 3.7 adds it.