What is the significance of escaping quotes when embedding JavaScript code within PHP echo statements?

When embedding JavaScript code within PHP echo statements, it is important to escape quotes to prevent syntax errors. This is because PHP uses double quotes to encapsulate strings, and if the JavaScript code also contains double quotes, it can cause conflicts. To solve this issue, you can escape the quotes within the JavaScript code by using the backslash (\) character before each quote.

echo "<script>
        var message = 'This is a message with \"double quotes\"';
        console.log(message);
      </script>";