Xtscript does not know about javascript as far as Xtscript is concerned it is just text to be output 
Xtscript is a server side script and is run before the page is sent to the browser
Javascript is a browser side script run by your browser when the page is viewed

1/ 
Certain characters are  reserved in the normal Xt:Script 'print' statement mostly $ ( ) (only as a pair) and ; (semi colon (only as the last character of a Xtscript line) )
also # symbols can be a problem and extra spaces may be stripped from the output
So you should use the 'print_raw' statement to output the parts of the javascript that use these characters.
Or javascript lines can be  broken onto separate xtscript 'print' lines ie: to break up bracket pairs
The safest method is to use 'print_raw' whenever possible

2/
'Print_raw' will not parse Xtscript variables  or bracket pairs (...) so you will need to use a normal 'print' statement to output Xtscript variables or to parse the contents of brackets  as a part of your javascript. 

3/
; (semi colon) cannot be the last character of a 'print' or 'print_raw' statement 
so when this is required by the javascript place it at the start of the next 'print' / 'print_raw' statement.
Or finish the line with a space and another ;(semi colon)

4/
spaces are ignored as the first or last characters in 'print' or 'print_raw' 
and multiple spaces may be ignored in 'print' screen output
So assign a Xtscript variable with a space for use where leading and trailing spaces are required