From time to time I have to pass some variables from PHP to JS script.
For now I did it like this:
var js-variable = "<?php echo $php-variable; ?>";
If you do want to use PHP, always encode with json_encode before outputting.
<script> var myvar = <?php echo json_encode($myVarValue); ?>; </script>