How can JavaScript code be outputted using PHP?

To output JavaScript code using PHP, you can use the `echo` or `print` functions in PHP to directly output the JavaScript code within the HTML document. This allows you to dynamically generate JavaScript code based on PHP variables or conditions.

<?php
// PHP code to output JavaScript
echo '<script>';
echo 'var message = "Hello, world!";';
echo 'console.log(message);';
echo '</script>';
?>