DEV Community

Discussion on: How would you refactor this JS function?

Collapse
 
qwertydude profile image
Chris Howard

This is a simple as I could get it while retaining readability

const lineChecker = (line = "", isFirstLine = false ) => {
  let document = isFirstLine ? `<h1>${line}</h1>` : `<p>${line}</p>`
  return line ? document : `<br />`
}
Enter fullscreen mode Exit fullscreen mode