CS Fundamentals Trainer · JavaScript · Security

Predict the output: an HTML-escaping helper with its replacements in this order.

function escapeHtml(s) {
  return s
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/&/g, '&amp;')
    .replace(/"/g, '&quot;');
}
console.log(escapeHtml('<b>"Tom & Jerry"</b>'));

Difficulty: medium

Answer this question

Related questions