You can drop a PHP value anywhere on a page, including inside a JavaScript variable declaration. I'm not sure about JavaScript's syntax, but if you had a variable in PHP named $myvar, it would go something like this:
<script type="javascript"><!--
var myVar = <?= $myvar; ?>
--></script>