Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #28986

Re: <!--

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: <!--
Date 2015-12-07 15:01 +0100
Organization PointedEars Software (PES)
Message-ID <5333913.KbEaQyBAFF@PointedEars.de> (permalink)
References <comment-20151207122517@ram.dialup.fu-berlin.de>

Show all headers | View raw


Stefan Ram wrote:

>   I tried the following with the Firefox console (one line of
>   input, one line of output, and one blank line is given below):
> 
> <
> SyntaxError: expected expression, got '<'
> 
> <!
> SyntaxError: expected expression, got '<'
> 
> <!-
> SyntaxError: expected expression, got '<'
> 
> <!--
> undefined
> 
>   So, when I input arbitrary symbols, it usually gives me a
>   syntax error.

Those are not arbitrary symbols; the first one is an operator that requires 
two operands.

>   But when I hit »<!--«, it does not say
>   »SyntaxError«, but »undefined«. Where is the production in
>   the grammar of JavaScript that allows this »<!--«?

I presume that “<!--”, at least at the beginning of a program, is parsed 
like “//” in Mozilla JavaScript was built into SpiderMonkey after people 
abused HTML comments to hide improperly escaped “script” element content 
from improperly working HTML parsers and the (properly working) W3C 
Validator.  That is one of the syntax extensions allowed by the 
“Conformance” section of ECMAScript Editions.

And so this program is empty; there is no remaining expression, the missing 
statement gets automatic semicolon insertion for the empty statement (ES 6, 
§ 13.4), and the program’s result is the “undefined” value.  See ES 5.1 for 
the /Program/ production; I could not find it in ES 6.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: <!-- Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-12-07 15:01 +0100
  Re: <!-- Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-12-07 20:33 +0100
  Re: <!-- John Harris <niam@jghnorth.org.uk.invalid> - 2015-12-08 11:02 +0000

csiph-web