Function to unquote string using JavaScript

Know how to unquote string in java script. Here is method to do this is best way sung js native slice string function.

<script type="text/javascript">
function unquote(str, quoteChar) {
      quoteChar = quoteChar || \'"\';
      if (str[0] === quoteChar && str[str.length - 1] === quoteChar)
        return str.slice(1, str.length - 1);
      else return str;
    };
    
    //test function
    document.write(\'<p> blank test \'+unquote("\'Hello World\'","\'") +\'</p>\');
    
    document.write(\'<p> blank test \'+unquote(\'"Hello World"\',\'"\') +\'</p>\');
    
    document.write(\'<p> blank test \'+unquote(\'$Hello World$\',\'$\') +\'</p>\');
            
</script>

Here is output.

js example