Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange String Behaviour with Spaces in Chrome Javascript Console

I cannot recreate this behaviour in the SO snippet engine, but I'm coming across some pretty funky string manipulation behaviour in Chrome (v46).

Have a look at this screenshot of the Chrome JavaScript console:

chrome example

To my mind, the result of the slice should be ( Here. That is, a bracket and then three spaces. Not a bracket and then one space, which is what it is currently offering me.

I checked the exact same commands in Firefox, which yield the results I was expecting:

firefox example

Can any one think of an explanation for the difference in output? Am I being dense?

Update

In regards to this being a duplicate of this, I believe this question does two things differently:

  • It is much clearer in its query
  • It asks why the phenomena occurs, rather than how to solve the problem
like image 837
shennan Avatar asked Oct 31 '22 16:10

shennan


1 Answers

This is just a DevTools issue, which most probably has been addressed with the following patch http://src.chromium.org/viewvc/blink?view=revision&revision=201091

It's about collapsing multiple white characters, as HTML rendering is done by default. The mentioned patch forces rendering using white-space: pre.

like image 152
Rafael Avatar answered Nov 12 '22 19:11

Rafael