how to send variable from .php file to .js file? I hope someone is able to help me.
The problem is the following one:
1)I have module in which a assign the variable in order to send to the template file php.tpl

&lt;?php
...
$testvar="Hello from alex!";
$variables['testvar'] = $testvar; 
...
?&gt;


This variable can be shown in the php.tpl file like 

&lt;?php print $testvar?&gt;


2)I have separated .js file
How can i get access to this varuiable inside .js file?

I know how it'll be if .js file is inside .php.tpl:

&lt;?php
$testvar="Hello from alex!";
?&gt;
&lt;script type="text/javascript"&gt;
var myVar = '&lt;?php print $testvar?&gt;';
&lt;/script&gt;


The problem is how to do the same if these two files .js and .php.tpl are separated?
You should use drupal_add_js() in your module, there is no need to output the variable in your .tpl.php:

drupal_add_js(array('YOURMODULE' =&gt; array('testvar' =&gt; $testvar)), array('type' =&gt; 'setting'));


And in your JavaScript, you can the access the value in Drupal.settings.YOURMODULE.testvar:

alert(Drupal.settings.YOURMODULE.testvar);


Direct usage of global variables (as suggested in your code sample) is a discouraged practice in JavaScript as it clutter the global namespace. Also, if your code is triggered on page load, check the "Behaviors" section in Managing JavaScript in Drupal 7 documention (the whole page is worth reading).