So I declared a variable empty in external JavaScript file which I am sourcing in my main HTML page and because I want to load that variable from PHP I am doing this but it doesn't seem to work.
<script src="./assets/js/script.js"></script>
<script type="text/javascript">var APIKey = <?php echo $API; ?></script>
script.js is the one having empty global variable like this:
var APIKey = "";
I have already declared $API in PHP and I know it's working because I tried echoing it as text and it works but for some reason it doesn't in script. Please help.
Thanks!