I am afraid that there is a very simple answer for this question but I’ve tried to search for a solution for some time now without any luck.
I’ve a very long string which often contains characters like semicolon (;), double and single quotes and perhaps other characters which can be harmful if not escaped probably.
When I try to run my JavaScript code, it comes up with the error “Uncaught SyntaxError: Unexpected identifier” and when I check what the Unexpected Identifier is, it is either the semicolon or a quote which is things is the end of the string.
In PHP there are built-in functions to prober render a text so it does not harm and prevent the code for breaking. Is there something equaling in JavaScript? I know I could just replace the characters but the problem is that I don’t always know which characters the string contains and therefore a more “general” function which takes care of escaping harmful characters would be very useful to have.