What are some best practices for integrating JavaScript within PHP scripts?

When integrating JavaScript within PHP scripts, it is important to separate the server-side PHP logic from the client-side JavaScript code. One common approach is to use PHP to generate the necessary JavaScript code dynamically within the HTML output. This can be achieved by echoing JavaScript code within script tags in the PHP file.

<?php
// PHP logic here

// Output JavaScript code within script tags
echo '<script>';
echo 'console.log("Hello from JavaScript!");';
echo '</script>';
?>