Any server side stuff such as php declaration must get evaluated in the host file (file with a .php extension) inside the script tags such as below
Then in the .js file, you can use the variable
alert(var1);
If you try to evaluate php declaration in the .js file, it will NOT work