Maybe you could do something like:
<script> var a = <?php echo $a; ?>; //for numbers </script>
That's one basic way of accomplishing what you want.
EDIT: As JiteshNK also pointed out, you could also do:
<script> var a = <?php echo json_encode($a); ?>; //safest solution </script>