Strange behavior of spaces with spaces in the Chrome Javascript Console

I cannot recreate this behavior in the engine of the sn snippet of SO, but in Chrome (v46) I encounter a rather funny behavior of string manipulation.

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

chrome example

In my opinion, the result of the slice should be ( Here . That is, a bracket, and then three spaces. Not a bracket, and then one space that it offers me.

I checked the same commands in Firefox that give the expected results:

firefox example

Can anyone think of explaining the difference in output? Am i tight

Update

As for being a duplicate of this , I believe this question does two things differently:

  • His request is much clearer
  • He asks why the phenomena occur, and not how to solve the problem.
+5
source share
3 answers

This is a DevTools problem, which was most likely fixed by the following patch http://src.chromium.org/viewvc/blink?view=revision&revision=201091

This is about folding a few white characters, since HTML is rendered by default. The above patch actions result using white-space: pre .

+3
source

In fact, there are no problems. Even I tried with Chrome v46, spaces are combined in devtools, which means that output / view looks like there is only one space, but actually there are 3 spaces. Check snapshot snapshot.

enter image description here

0
source

Don't be fooled: Chrome’s behavior is correct. It is simply a font used in the debug console that makes adjacent spaces more subtle. You can verify this by checking string.slice(1).length .

-1
source

Source: https://habr.com/ru/post/1235426/


All Articles