var userString = `var a='sister\'s'`
eval(userString) //error
I will get the user string and do eval, it throws parse error since the string is escaped. How to eval it properly , i saw we can ,make some regex handling and replace quotes but i am not sure it will work efficiently since the user's javascript content can be any javascript content. Is there any universal method?
we can make use of string.raw api
var userString = String.raw`var a='sister\'s'`;
eval(userString) //no error and variable 'a' will have the expected value.