How to reference PHP in Javascript

To answer the question, no: It’s not an issue with formatting, it’s as jdm2112 explains the matter. You can, however, “send” the variable , or have it plucked from the server, either via an Ajax call as jdm2112 suggests or as set by wp_localize_script(). Which you use will likely depend on what the script does and when and how it’s run.