I am trying to use JavaScript to determine if a field is empty.
Here is the scenario: If the result.title field is not available or empty, I need to display a default title.
These are the conditions:
- If the result.title is available, show that as the title.
- If result.title is empty and name is present, show the string "${name} matches".
- If result.title is empty and name is not present, show the string "default title".
This is what I have attempted so far:
const defaultTitle = result?.title ?? "default title";
However, this does not account for an empty title field and whether the name is present or not.
Can someone please assist me with this? Thank you.
Thank you!