What potential issues can arise when trying to output both a counter and a variable in JavaScript from PHP?

When trying to output both a counter and a variable in JavaScript from PHP, the potential issue that can arise is that the JavaScript code may not execute as expected due to improper syntax or concatenation. To solve this issue, you can use PHP to echo the JavaScript code with the counter and variable properly concatenated within the script tags.

<?php
$counter = 0;
$variable = "Hello World";

echo '<script>';
echo 'var counter = ' . $counter . ';';
echo 'var variable = "' . $variable . '";';
echo '</script>';
?>