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, '<')
.replace(/>/g, '>')
.replace(/&/g, '&')
.replace(/"/g, '"');
}
console.log(escapeHtml('<b>"Tom & Jerry"</b>'));
Difficulty: medium