Hi @krishnags ,
the documentation on that one is a little bit misleading. In fact, i do it like this:
{% assign mysnippetname = "this/is/my/fancy/snippetname" %}
{% assign snippetvalue = snippets[mysnippetname] %}
BUT 🙂 - this is liquid, which is executed on the server.
I think, you want the snippet in a javascript variable. This requires a littbit more work. Use the upper code to get the snippet. Then add to your template:
<script>
var myjscontentsnippet = "{{ snippetvalue | strip_newlines | replace: '"', ""e;" }}";
</script>
then you have the content in the js variable myjscontentsnippet. The strip_newlines is neccessary, because newlines would break the js code, the replacement of doublequotes to escaped version (you could also use '\"' as a replacement) is needed, because the doublequoted string would end there.
Of course, you could also use single quotes as the outer quotes and replace singlequotes in your snippets.
This is, how i do it.
Hopefully it fulfilles your needs as well.
Have fun,
Christian