I Have an issue where user last name(adfs2"k) which has double quote, whenever I need to edit the last name and click on a button, it throws an error
Uncaught SyntaxError: missing ) after argument list
I have tried the double quote escape, but it still throws
lastName = lastName.replace(/\"/g,"\\\"");
and this is the function, i'm using
"javascript:editUserEmailPopup(' + "'" + firstName + "'" + ',' + "'" + lastName + "'" + ');"
As @T.J. Crowder suggests in his comment, one cause of this issue is embedding your function call within an HTML attribute. Using these inline-event-handlers can lead to problems like this as well as unmanageable code. The alternative is to use an external script tag, or to inline a script tag.
However, even within an isolated script, this code has some issues that make it unclear what it should even do and does not work. I believe the code is meant to return the firstName variable surrounded by double quotes, followed by the lastName variable surrounded by single quotes. The code is unclear but this solution should be able to fix it:
const firstName = 'asd5"3'
const lastName = "jfni8'543"
console.log(`"${firstName}", '${lastName}'`)
This syntax of embedding variables into strings and being able to use double quotes and single quotes without escaping them is called Template literals:
Template literals are enclosed by the backtick (
) (grave accent) character instead of double or single quotes.
Template literals can contain placeholders. These are indicated by the dollar sign and curly braces (${expression}). The expressions in the placeholders and the text between the backticks () get passed to a function.
(From MDN)