DEV Community

Discussion on: 5 JavaScript Practices That Will Help You In The Long Run

Collapse
rawas_aditya profile image
Aditya Rawas

This is out of context because like you I used to get across code lik

function createList({ list = [] } = {}) {
  return `
    <ul>
      ${list.map((item) => {
        return `
          <li>
            ${item.title}
          </li>
        `
      })}
    </ul>
  `
}
Enter fullscreen mode Exit fullscreen mode

Problem with this code is I can item.title could have HTML or javascirpt code that will hit you hard later.
like

item = {
  title:"<script>for (var i = 0; i < Infinity; i++) {}</script>"
}
Enter fullscreen mode Exit fullscreen mode

above example will break your page.

Solution; USE JSRENDER