Is it possible to hide JavaScript code in a PHP page effectively?

It is not possible to completely hide JavaScript code within a PHP page because JavaScript code is executed on the client-side, meaning it needs to be visible to the client's browser. However, you can obfuscate the JavaScript code to make it more difficult for someone to read and understand.

<?php
$jsCode = "alert('Hello, World!');";
$obfuscatedCode = base64_encode($jsCode);

echo "<script>";
echo "eval(atob('$obfuscatedCode'));";
echo "</script>";
?>