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

J. Lester Novros II lester at denhaag.org
Fri May 12 19:04:45 CDT 2006


Triche Osborne wrote:

       [snip snip snip]

> well.) It's interesting to note that it isn't considered a complete 
> statement in itself. The following isn't complete:
> 
> ( var ) ? 'this' : 'that';

FWIW, strictly speaking, that isn't altogether true. For example, I can do this:

    document.getElementById('someID').title =
       navigator.platform == 'MacPPC'
       ? 'command click to do some stuff'
       : 'ctrl click to do some stuff';

Or, assunming someNumber and someOtherNumber are numbers, even this:

    span.appendChild(
       someNumber < someOtherNumber
       ? document.createTextNode('some text')
       : document.createTextNode('some other text')
    );

IOW, the result of ternary statement dosn't necessarily have to be assigned to a 
variable.

l8R lES
-- 
m$ Office is the bludgeon Microsoft uses to keep other software vendors in line.
Without Office, Microsoft is just a company with an archaic and insecure OS.
                                                               Robert X. Cringely
                                                           http://www.denhaag.org




More information about the Javascript mailing list