Let me emphasize part of the first quote
JavaScript ignores spaces, tabs, and newlines that appear between tokens in programs
Programs are divided into tokens. For example, the following program
var x = "abc123";
has 5 tokens, namely, var
, x
, =
, "abc123"
and ;
. If you put more spaces between the tokens,
var x = "abc123" ;
it doesn't matter. But if you put a space inside of a token, then it can change the program. For example,
va r x = " a b c 12 3";
does not compile.
This difference is why the two statements are not contradictory. A comment is a single token that is ignored. If you put a newline in the middle of a comment, then you are not putting space in between tokens in a program, you are putting a space in the middle of a token.
A //
comment ignores the rest of the content on the line. Since bookmarklets only contain 1 line, you would be commenting out everything after the //
. In a normal script, you can have many lines, so you don't have the same problem.
If you are curious how this is specified, here's the relevant part of the grammar in the ECMAScript 5 specification:
SingleLineComment ::
// SingleLineCommentCharsopt
SingleLineCommentChars ::
SingleLineCommentChar SingleLineCommentCharsopt
SingleLineCommentChar ::
SourceCharacter but not LineTerminator