Transfer a variable value from php to js?

Tell me where is the error?
Trying to pass variable $expanded from php to js, write js in the following:
var expanded='<?php echo $expanded?>';
But he expended writes the value ""as just text, not executing the php code.
July 8th 19 at 16:20
1 answer
July 8th 19 at 16:22
Solution
to write it is not necessary in the js file that has nothing to do with php, a php file that generates the page.

Find more questions by tags JavaScriptPHP