I didn't read through all of the other comments so someone else may have already suggested this one, but if the objective is to minimize conditions that are explicitly checked, start with the last case like this:
const lineChecker = (line, isFirstLine) => { if (line === "") { return "<br />"; } else if (!line) { return ``; } else if (isFirstLine) { return `<h1>${line}</h1>`; } else { return `<p>${line}</p>`; } };
I also got rid of the concats with the unnecessary local variable.
When using the early return method, you don't need else if. Just use if.
else if
if
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I didn't read through all of the other comments so someone else may have already suggested this one, but if the objective is to minimize conditions that are explicitly checked, start with the last case like this:
I also got rid of the concats with the unnecessary local variable.
When using the early return method, you don't need
else if
. Just useif
.