Is it recommended to use htmlspecialchars() function with specific flags when escaping characters in PHP strings for JavaScript functions?

When escaping characters in PHP strings for JavaScript functions, it is recommended to use the `htmlspecialchars()` function with the `ENT_QUOTES` flag to properly escape characters that could cause issues in JavaScript code. This ensures that special characters like quotes are properly escaped, preventing any potential security vulnerabilities or syntax errors in the JavaScript code.

$string = 'This is a string with "quotes" and <html> tags';
$escaped_string = htmlspecialchars($string, ENT_QUOTES);
echo "<script>var jsString = '$escaped_string';</script>";