There are times when I bind a variable, use it to check a condition, and then return it based on the result.
const val = getAttribute(svgEl, "fill");
if (val) {
return convertColorToTgml(val);
}
const ancestorVal = svgAncestorValue(svgEl, "fill");
if (ancestorVal) {
return convertColorToTgml(ancestorVal);
}
return "#000000";
This code can be confusing to me. It would be easier if I didn't have to assign each variable before checking the conditions. Is there a more concise way to achieve this in JavaScript/TypeScript?