JSP:
<% final String data = "some test with ' single quotes"; %>
<script>
var str = '<%= data %>';
<script>
The result is (JavaScript):
var str = 'some test with ' single quotes';
Uncaught SyntaxError: Unexpected identifier
How do I replace this single quote with \'
to avoid a JavaScript error?