SOURCE

function htmlencode(s){
    var div = document.createElement('div');
    div.appendChild(document.createTextNode(s));
    var result = div.innerHTML;
    div = null;
    return result;
}
function htmldecode(s){
    var div = document.createElement('div');
    div.innerHTML = s;
    var result = div.innerText || div.textContent;
    div = null;
    return result;
}

const log = console.log;

log(htmlencode("<div>3>5 & 666</div>"));
log(htmldecode("&lt;div&gt;3&gt;5 &amp; 666&lt;/div&gt;")) 
console 命令行工具 X clear

                    
>
console