Now loosely related to optional Cheney we got another nice feature in typescript which helps us deal
with knowledge data and that feature is called knowledge coalescing.
Now imagine you have some data some input where you don't know with certainty whether it's now or on
the find or whether it's actually a valid piece of data.
For example user input could be now let's say now again here we hard code doesn't to typescript hence
typescript knows that this is now.
But if you're fetching this through some DOM API where you don't know it with certainty or if you're
getting this from a back end then you might not know in advance and typescript might not know where
it is is null or not if you didn't want to store this in some other constant or variable like stored
data.
You might want to make sure that if it is now you store a fallback value.
Now you can do so with the logical or operator where you store a default where you get that second value
of the first one is undefined or.
Now if it's false C to be precise.
The problem with this approach is if this is actually not now or undefined but let's say an empty string
it is treated as a false value and data for debt default fallback value will kick in.
So if I set a console lock stored data here you will see that this prints default now maybe it is what
you want and in that case this is a perfectly fine solution but if you want to keep that user input
or whatever data you're working with unless it really is now or undefined then you need another approach.
Because here we would treat this as false and use the fallback.
But maybe you want to keep an empty input just null or undefined should be handled differently for that
type could also has an operator.
The double question Mark.
Operator this is called The Knowledge coalescing operator and it means if this is null or undefined
and really just that not an empty string not zero really just now or undefined then we'll use the fallback
if it's not Nala on the find.
We'll use that value.
So in this scenario here this compiles and you see we stored the empty string.
Hence I'm not printing anything here.
This is the empty string.
If is on the other hand let's say is undefined here in safeties.
You say now it says default because thanks to this double question Mark.
Operator we fall back to this.
Well back and therefore here we got a number very useful feature which can help you deal with knowledge
or undefined values with grace.