DEV Community

Discussion on: How would you refactor this JS function?

Collapse
 
utsavladani profile image
Utsav Ladani

If line is plain text, then you should use object to add HTML in document instead of document += ....

const header = document.createElement("h1")
header.textContent = line
document.append(header)
Enter fullscreen mode Exit fullscreen mode

It makes function faster