For instance say I have the string:
var name = \'Mc\'Obrian\'
I want to be able to escape the the first quote and the last quote only, not the
use \
to escape the single quote like so:
var name = 'Mc\'Obrian'
The following will properly escape the single quote given your current code:
var name = 'Mc\'Obrian'
I would encourage you to read the following tutorial about strings. If you are interested in performance considerations, read this question.
var name = 'Mc\'Obrian'
or
var name = "Mc'Obrian"