Do you know the expression ? when using it like this:
data?.name
I mean what does this question mark (?) in-between the data and the point do?
Do you know the expression ? when using it like this:
data?.name
I mean what does this question mark (?) in-between the data and the point do?
This is called "Optional chaining".
Say you make an axios request and expect the response.data object.
You don't KNOW if data will be there, but you expect it to.
The question mark is a shorthand for writing
data && data.name
If data is undefined, the data.name code does not run and thus you don't get an error (cannot access name of undefined)
it is called Optional chaining (?.)
, and basically it will return unidentified instead of throwing an error
you can read more about it here
https://developer.mozilla.org/enUS/docs/Web/JavaScript/Reference/Operators/Optional_chaining