Ternary statement [was Re: [Javascript] Show and hide multiplediv tags]

Abyss - Information Info at Abyss.ws
Sat May 13 18:37:40 CDT 2006


Hi all,

I didn't mean for this big mess to come out of it..

I honestly ...after looking at those code you all so diligently wrote in 
order to prove a point (to which i am not saying who is right or wrong) - 
feel insignificant ("small") in my javascript ability - even the females 
like triche have a "bigger"...err....understanding as such...

My point is its not worth nit picking if its a right or wrong thing, the 
most important thing is that it works :)

We do not need to bother (nor...IMO really have to care) if its is right or 
wrong as developers we just need to know it works - that way we can make 
sure we can worry about more important things
like family and stuff - too much worry and stress is put on stuff like 
this....


anyway....
Thanks

Abyss.




----- Original Message ----- 
From: "liorean" <liorean at gmail.com>
To: "[JavaScript List]" <javascript at latech.edu>
Sent: Sunday, May 14, 2006 5:42 AM
Subject: Re: Ternary statement [was Re: [Javascript] Show and hide 
multiplediv tags]


On 13/05/06, Triche Osborne <wdlists at triche-osborne.com>
> The point was that it has to be part of a completed statement--that is,
> the returned results must be used in some way.

No, they don't. Expressions may be Statements in and of themselves if
they appear as ExpressionStatements. The difference is that then the
return value is automatically discarded.

> In both of your examples above, this is what's happening: In the first,
> the result is assigned to document.getElementById('someID').title; in
> the second, it determines which text is appended to span.appendChild.

True... but those were bad examples.

> Neither this . . .
>
> navigator.platform == 'MacPPC'
>  >       ? 'command click to do some stuff'
>  >       : 'ctrl click to do some stuff';
>
> NOR this . . .
>
>  >       someNumber < someOtherNumber
>  >       ? document.createTextNode('some text')
>  >       : document.createTextNode('some other text')
>
> form a complete statement in and of themselves.

Wrong. They are both fully valid ExpressionStatements, and thereby
they do form complete statements. They are pointless since they
discard the return value, but they are complete statements.

Let's try at an example which uses side effects instead:

    'body' in document?
        document.body.appendChild(
            document.createTextNode('document.body property exists,
which in all probability means the document is HTML')):
        document.documentElement.appendChild(
            document.createTextNode('document.body property doesn't
exist, which in all probability means the document is either plain XML
or XHTML'));

Return value might be discarded, but the expression is a statement in
and of it's own, and will have side effects on the DOM.




Oh, and just for the record: "ternary operator" means
operator-with-three-operands. The name of this specific operator is
the "conditional operator". It just happens to be the only ternary
operator in ECMAScript. You don't go around calling "--" for the
"unary operator" or "instanceof" (just to grab a totally ridiculous
example) for the "binary operator", do you?
Unary, binary or ternary just explains how many operands they have,
the important thing is their functionality.
-- 
David "liorean" Andersson
<uri:http://liorean.web-graphics.com/>
_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript





More information about the Javascript mailing list