textLineHeight = textStyles && textStyles.lineHeight;
means set textLineHeight
to textStyles.lineHeight
if textStyles
is truthy and it has a property lineHeight
which is also truthy.
&&
is often referred to as the guard operator in JavaScript, since its short circuiting evaluation ensures that textStyles.lineHeight
will not be evaluated unless textStyles
is defined. This avoids an error if it may indeed be undefined.
wrapper.height = (height || bBox.height || 0) + 2 * padding;
Here, the ||
means use height
if it is truthy otherwise use bBox.height
if that is truthy, and finally fallback to 0
if neither are truthy. ||
is often called the default operator in JavaScript as it allows one to specify a value to use in case the expression on its left hand side is falsy.