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.