Escape html in javascript

function escape_html(text) {
    return text
        .replace(/&/g, "&")
        .replace(/</g, "&lt;")
        .replace(/>/g, "&gt;")
        .replace(/"/g, "&quot;")
        .replace(/'/g, "&#039;");
}

console.assert(escape_html("<hr>") == "&lt;hr&gt;")