How do you safely wrap a JS string variable in double quote chars?
- by incombinative
Obviously when you're creating an actual string literal yourself, you backslash escape the double quote characters yourself.
var foo = "baz\"bat";
Just as you would with the handful of other control characters, like linebreaks and backslashes.
var bar = "baz\\bat";
but when you already have a variable, and you're wrapping that existing…