JSFiddle - React, Tailwind, and code Playground

HTML

<input type="text" id = "fillme" value="aa ///\\\"/>
<button id="button" >clickme</button>

JavaScript

function addslashes(str) {
str=str.replace(/\\/g,'\\\\');
str=str.replace(/\'/g,'\\\'');
str=str.replace(/\"/g,'\\"');
str=str.replace(/\0/g,'\\0');
return str;
}
function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\0/g,'\0');
str=str.replace(/\\\\/g,'\\');
return str;
}
    $("#button").click(function(){
        str=$("#fillme").val();
alert("before calling the function addslashes : "+str);
        str = addslashes(str);
      alert("after calling the function addslashes : "+ str);

   
});