const sampleStr = "Alan said, \\"Peter is learning JavaScript\\". It needs to be either 'Jo\'hn' or "Jo'hn" . Our aim is that we want to print in the console like: ""Geeks" for "Geeks" is 'the' best 'platform'". User1253338400 posted Hi I have the following: recd.selectQry = 'select Account.Id from Account where Account.Id IN ('87654321')'; How can i format this / escape the single … Escape single quote Can you give me the correct syntax to achieve this. Use encodeURI () or encodeURIComponent () instead. Not clear. In JavaScript, you can escape a quote from considering it as an end of string quote by placing a backslash () in front of the quote. escape single quotes However, if you want your JavaScript code to be independently escaped for any context, you could opt for the native JavaScript encoding: ' becomes \x27 " becomes \x22 Escape variable in single quotes in single quote Escape quotes in JavaScript (8) " would work in this particular case, as suggested before me, because of the HTML context. Escape single quotes(‘) in JavaScript | Tech Tamasha Use Double or Single Quotes in JavaScript