1

Interesting little pickle:

I was using JSbin to practice converting single quotes to double quotes. The readout in the JSbin console kept inexplicably giving me "\". Then when I tried running the same code in the chrome console, the switch worked fine. (Yes, I am aware that it converted the ' in "I'm"--that is not the question at hand though.)

Any idea why jsbin might have given me those backslashes in the console output?

Jsbin screen shot

Goodword
  • 1,565
  • 19
  • 27
  • 2
    There's no problem, it's just different ways to represent the same thing. When displaying strings, chrome console puts double quotes around it, while jsbin does something tries to represent the string as you would've written it in your code, that is with escapes – Zirak Oct 29 '14 at 21:17
  • Word, I am going to edit this so that it doesn't say 'problem.' I don't know what it is...'curiosity,' 'pickle.' The thing is, those double quotes around the backslash are definitely not what I was looking for. – Goodword Oct 29 '14 at 21:18

1 Answers1

6

Since my comment didn't satisfy you, let's look at the sources.

Chrome dev tools, ConsoleViewMessage.js:

elem.createTextChild("\"");
elem.appendChild(elementWhichHoldsOurString);
elem.createTextChild("\"");

As you can see, the dev tools writes an a double quote, followed by our string, followed by another double quote.

jsbin, proxy-console.js is what handles your console.log arguments. As you can see, it calls stringify, which explicitly escapes double quotes in strings.

Zirak
  • 38,920
  • 13
  • 81
  • 92