What is the difference between echoing a PHP variable and simply calling it in a JavaScript script?

When echoing a PHP variable, the variable's value is output directly into the HTML document when the PHP script is executed. However, when calling a PHP variable in a JavaScript script, the variable's value needs to be passed from PHP to JavaScript using inline script tags or AJAX requests. This is because PHP is a server-side language while JavaScript is a client-side language, so they run in different environments.

<?php
$php_variable = "Hello from PHP!";
?>
<script>
var js_variable = "<?php echo $php_variable; ?>";
console.log(js_variable);
</script>