PHPからjavascriptに値を渡す方法

下記のようにPHPの値をjavascriptに書き込んで使用します。

<script>
var i=<?php echo $i; ?>; 
</script>