How can potential issues with PHP and JavaScript integration be avoided when creating pop-up windows?

Potential issues with PHP and JavaScript integration when creating pop-up windows can be avoided by properly escaping PHP variables before passing them to JavaScript functions. This can prevent syntax errors or security vulnerabilities that may arise from unescaped characters in the data being passed.

<?php
$popup_message = "Hello, world!";
?>
<script>
var popupMessage = "<?php echo addslashes($popup_message); ?>";
alert(popupMessage);
</script>