let p = '<h1>escapeForHTML<h1>';
let regex = /[<>&]/gi;
let r = new Map([
['>','>'],
['&','&'],
['<', '<'],
]);
let f = c => r.get(c)
document.body.insertAdjacentHTML("afterbegin",p);
document.body.insertAdjacentHTML("afterbegin",p.replace(regex,f));