What are the potential pitfalls of using inline JavaScript within PHP code, as seen in the provided example?

Potential pitfalls of using inline JavaScript within PHP code include mixing logic with presentation, making the code harder to maintain and debug. It can also lead to security vulnerabilities if user input is not properly sanitized. To solve this issue, it's recommended to separate PHP logic from HTML and JavaScript code by using a templating engine or separating them into different files.

<?php
// Separate PHP logic from HTML and JavaScript code
$data = "Hello, World!";
?>

<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
</head>
<body>
    <p><?php echo $data; ?></p>
    <script>
        // Use PHP variables in JavaScript code
        var message = "<?php echo $data; ?>";
        alert(message);
    </script>
</body>
</html>