Escaping back slash javascript through regex

Hi, I am trying to escape backslash using regular expression in javascript. See this link please:
link. It does not show backslash in the console but it does in the return value. Is the back slash escaped or do I need to try any other way. Is it possible to escape backslash using regular expression because "replace function " does not seem to make a difference in output.

function abc(str){
	let regex = /\\/g;
	//str = str.replace(regex, "");
	console.log("str: ", str);
	return str;

let str = "I can\'t do it. I don\'t know.";

See what happens when you put "I can't" as the final line in the editor.

I get I can\'t'. does that mean backslash is always there for special characters whether \ is added or not? but will not be printed .

I think applies its own escaping when putting back user output.
For example, all string is in single quote form. So, to eliminate possible confusion, it chooses to escape any single quote inside the single quote string.

1 Like

It could be the reason. same results with chrome developer tool.