I found a bug in my JavaScript code that I have isolated to a string replace that is acting in a way I didn’t expect. Here is an example of the code:
var text = "as";
text = text.replace(text,"$\'");
console.log(text);
This prints an empty string to the console. I was expecting it to print $’ to the console. Can anyone explain this?
In order to use
$in resulting string, use$$as$has special meaning in JavaScript Regular Expressions and Stringreplacemethod: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_string_as_a_parameter