Js var from php var

Isn’t this how you turn a php var into a js var?

var url = "<?php echo $_SESSION['url'] ?>";

if so, why does the php code display in an alert() instead of the value of $_SESSION[‘url’]?

That would be due to the HTML page not being interpreted as a php file.