DEV Community

Discussion on: How would you refactor this JS function?

Collapse
 
andrehtissot profile image
André Tissot

I tend to prefer a balance between smaller and readable code:

const lineChecker = (line, isFirstLine) => {
  if(line === "") return "<br />";
  if(isFirstLine) return `<h1>${line}</h1>`;
  return `<p>${line}</p>`;
};
Enter fullscreen mode Exit fullscreen mode

But as many things, this is just a personal preference, and the team conventions should always supersede.