Does js have htmlspecialchars and htmlspecialchars_decode functions similar to php?

$x= "

test

"; echo htmlspecialchars($x);

test

$y = htmlspecialchars($x); php > echo htmlspecialchars_decode($y);

test

There doesn"t seem to be a ready-made function in

js, is it?
htmlspecialchars and htmlspecialchars_decode?

Jul.22,2021

doesn't seem to have it, but you can do it in the browser

function encode(s) {
    const div = document.createElement("div");
    div.innerText = s;
    return div.innerHTML; 
}
Menu