I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.
If a space is in quotes then it is actually kept any spaces outside of quotes are basically discarded. Generally just do the indentation and line breaks for sanity to be able to quickly see where stuff stops and starts but inside of quotes (when defining a string) the spaces are literally in there and aren’t removed.
Strings are how the regular text on page is represented in the JS version of the page called the JSDOM and spaces need to be preserved for anything shown to the user.
It’s much simpler than this, you’re mashing up lots of different unrelated things here: " " (ie the space between those quotes) is a character, same as a or 1 or 😬.