This package simplifies the process drastically.
enable the moudle
pass php vars
console.log(php.aa); // 32 console.log(php.bb); // cc
You can your own namespace in settings.php like
$settings['js_namespace'] = 'phpjs';