How can the use of double and single quotes in PHP affect the output of JavaScript code?

When using PHP to output JavaScript code, the use of double and single quotes can affect the output if not handled correctly. This is because PHP uses double quotes for string interpolation, and if JavaScript code contains double quotes, it can break the string. To solve this issue, you can escape the double quotes in the JavaScript code using a backslash (\) before each double quote.

<?php
$js_code = "var message = 'This is a \"quoted\" message';";
echo "<script>{$js_code}</script>";
?>