Can I set a JS variable to a Twig output tag? This came out of a previous question

I need to set a variable of a tag group that I can reference in jquery for use with a plugin.

I'm declaring this variable in a  tag so my included js files can access it.

Here's what I want to do:

&lt;script type="text/javascript"&gt;
    var gameTags = {{ craft.tags.group('gameTags') }};
&lt;/script&gt;


Javascript clearly doesn't like that syntax, so I tried setting the variable with Twig and calling that:

{% set gameTags = craft.tags.group('gameTags') %}

&lt;script type="text/javascript"&gt;
   var gameTags = gameTags;
&lt;/script&gt;


JS considered that undefined.

I'm probably going about this the wrong way. I'm relatively new to javascript and very new to craft, so I'm a little stumped.
In your first example, you are outputting an ElementCriteriaModel. That is a query for tags rather than the tags themselves. It doesn't output anything usable by JS You're almost doing the same in the second example, except that your reference to gameTags in the JS is just referencing itself rather than any Twig output.

What you want to do is to query the tags and output in the way that JS can use. Something like this:

&lt;script type="text/javascript"&gt;
    var gameTags = [{% for tag in craft.tags.group('gameTags') %}"{{ tag.title }}",{%endfor %}];
&lt;/script&gt;


That should output a JS array of strings with each string being a tag. Something like below.

&lt;script type="text/javascript"&gt;
    var gameTags = ["action","adventure","platform","rpg","sports",];
&lt;/script&gt;


If you're a stickler for commas in arrays, there's ways to not output that after the last tag.