Re: .join('') !== '' + a + b; // for some 'a' and 'b'




"Thomas 'PointedEars' Lahn" <PointedEars@xxxxxx> wrote in message
news:4A6E328C.7010602@xxxxxxxxxxxxxxxxx
Paul E. Schoen wrote:

True, but examples really work well, as long as the anomaly is obvious
or
explained.

In what way is the above an explanation of what is really going on?

The one seemed obvious until your more detailed explanation below, although
that made it necessary to look deeper into the syntax.

I think I understand these examples.

Having read your entire reply, I seriously doubt that. Indeed, I doubt
that
Jonathan himself understood what is really going on here.

The missing comma seems like an obvious error. But perhaps it is one of
those things that is sometimes optional?

No, it isn't.

// Syntax gotcha.

This is a technical newsgroup. Please do not propagate script-kiddie
terminology here (or elsewhere, hopefully).

What other term do you suggest that is more meaningful? "Anomaly?"
"Confusing delimiters?" "Often misunderstood construction which can result
in errors?" I think "gotcha" is good enough.

[[1,2,3], [4, 5, 6] [7, 8, 9]][2] === undefined || ddt('Syntax Gotcha
1');

This is not a syntax error because it is initializing and accessing an
Array
object of two elements, one an Array object reference and one
`undefined',
being equivalent to

[ [1, 2, 3], [4, 5, 6][9] ][2]

How does [7,8,9] become [9]?


or

var a = [1, 2, 3];
var b = [4, 5, 6][9];
[a, b][2]

which MUST evaluate to `undefined' (even if b != undefined).

This peculiarity draws from the fact that the syntax of Array
initializers
and bracket property accessors is similar, and that the comma serves both
as an element delimiter in an Array initializer (ECMAScript Language
Specification, Edition 3 Final [ES3F], section 11.1.4) and as an operator
(ibid., section 11.14) in an expression that is allowed as parameter of
the
bracket property accessor syntax (ibid., section 11.2.1):

I tried to read those sections and found the unfamiliar term "elision",
which AFAICT is removal of unnecessary brackets or other delimiters when
operator precedence makes them superfluous. Not that that helps a whole
lot. Stuff (pardon, information) I found:

http://www.mpi-inf.mpg.de/departments/rg1/conferences/deduction08/slides/kohlhase-michael.pdf
http://www.nczonline.net/blog/2007/09/09/inconsistent-array-literals/
http://blogs.msdn.com/jscript/archive/2007/10/29/ecmascript-3-and-beyond.aspx


[6, 5, 4] [3, 2, 1] === [6, 5, 4][1] === 5

[[1,2,3], [4, 5, 6], [7, 8, 9]][2] === undefined || ddt('Syntax Gotcha
2'); //error

The error occurs because the first operand of `||' is `false' which
forces
the second/next operand to be evaluated, and `ddt' there is either not
defined (ReferenceError) or its current value is not callable
(TypeError).
(Although those who had read and understood the corresponding sections of
ES3F would have known, you should have checked/posted the error message.
"error" is hardly an error description to work with.)

In this case "error" is simply the execution of the function ddt(), which
adds the text parameter to the string 'error: ' and echoes it in the WSH.


But this seems confusing (I added some stuff):

-1 % 5 === -1 || ddt('-1 % 5 === -1');
-5 % 5 === -5 || ddt('-5 % 5 === -5'); //error

Same here.

-5 % 5 === 0 || ddt('-5 % 5 === 0');

Since -5 % 5 === +0 (-5 â?¡ 0 (mod 5)), the second operand is never
evaluated
(ES3F, 11.11).

-5 % 5 === -0 || ddt('-5 % 5 === -0');

Same here. -0 is treated like +0 by `===' (ES3F, 11.9.4 and 11.9.6).

0 === -0 || ddt('0 === -0');

And here.

0.0 === -0.0 || ddt('0.0 === -0.0');

And here. Apparently you have not understood the ECMAScript Number type
and
(Strict) Equals operator. Read ES3F, sections 8.5 and 11.9.

I can't understand why the strict equality operation would not
differentiate between the two. But of course it is so defined in the
standard.

Now the following seems to be a bit strange:

x = 0.0;
y = -0.0;
WScript.echo( 'x= '+ x + ' y= ' + y ); // x= 0 y= 0
WScript.echo( '1.0/x= '+ 1.0/x + ' 1.0/y= ' + 1.0/y ); // x= Infinity
y= -Infinity
WScript.echo( 'Is x===y? ' + Boolean.prototype.toString(x===y) ); //false
WScript.echo( 'Is 0===-0? ' + Boolean.prototype.toString(0===-0) );
//false
(0 === -0) || ddt('0 === -0'); //true
(0/1 === -0/1) || ddt('0/1 === -0/1'); //true

The variables x and y are clearly different, although they are interpreted
as simply zero for the purpose of the echo. Their inverses show as positive
and negative infinity. Apparently the last two statements evaluate as true,
else the ddt() would have indicated an error. But the evaluation in the
Boolean.prototype.toString evaluate the expressions as false.

-6 % 5 === -1 || ddt('-6 % 5 === -1');

Same here. Apparently you have not understood the `||' operator either.

I believe I do.


I never really thought about what happens to a remainder or modulo
operation when less than zero. But I thought there was a difference
between
0 and -0. Apparently not. Perhaps only for type float, and adding a
decimal
does not seem to perform the conversion as I had expected.

Obviously now you do not understand the (only) ECMAScript Number type
which
is defined as an implementation of IEEE-754 double-precision floating
point
numbers. RTFM, RTFFAQ, STFW.

The IEEE-744 double precision floating point implements a negative zero:
http://en.wikipedia.org/wiki/%E2%88%920_(number)

And I don't know if there is any way to ensure that a variable is
interpreted as a float. Apparently adding the decimal works. But something
seems wrong with the expression evaluation on the left side of the logical
OR expression.

WScript.echo( 'Is 0===0.0? ' + Boolean.prototype.toString(0===0.0) );
//false
(0 === 0.0) || ddt('0 === 0.0'); //true

Paul


.



Relevant Pages

  • Re: Modifying Array inside While statement
    ... > I have a perl script that takes an array and processes the arguments ... Where did you learn this syntax? ... that glob is operating on the string composed of the ... evaluation of the whileconditional. ...
    (comp.lang.perl.misc)
  • Re: Perlish map() function
    ... the reference material, the Array constructor was introduced in JavaScript ... evaluation would result in a ReferenceError. ... identifier shows that it is true. ...
    (comp.lang.javascript)
  • Re: How to do "Compile time" initialization of record array?
    ... It should be noted that there is proposed syntax for C# 3.0 which will ... public struct MyStruct ... What actually gets compiled is the same array initialization as there is ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: It Hurts When I Do This
    ... We do have a syntax that means the entire array - the array name. ... I disagree that it helps to use a special notation to indicate that ... I think it a mistake to throw all this kind of thing in the language. ...
    (comp.lang.fortran)
  • Re: What does this script means?
    ... first is a dot-notation property accessor. ... special array accessing syntax. ... In my experience (including reading 400000 odd javascript relate Usenet ...
    (comp.lang.javascript)