[Javascript] Show and hide multiple div tags
Cutter (JS Related)
java.script at cutterscrossing.com
Thu May 11 21:46:51 CDT 2006
Triche,
Great explanation. Took me a long time to figure that out the first time
I saw it (many moons ago). Thanks for putting that out there so clearly,
very well done.
Cutter
Triche Osborne wrote:
> Abyss - Information wrote:
>> Yes I understand that.
>>
>> I was just wondering (to which i will yahoo a ternary statement in a
>> minute)
>>
>> why and how does it work with the? and the :
>>
> The question mark is the ternary operator. Just as an equal sign (the
> assignment operator) is parsed by the interpreter as "store this piece
> of data at a place designated by this name," the question mark is
> intepreted as "if the statement that preceeds this question mark . . ."
> The question mark is always immediately followed by the true condition.
> The colon is the "else" and is always followed by the false branch.
>
> If you could see it as the interpreter does, it would be something like
> this:
>
> (1) var2 = var ? 'this' : 'that';
> ^ if var is
>
> (2) var2 = var ? 'this' : 'that';
> ^ TRUE, this
>
> (3) var2 = var ? 'this' : 'that';
> ^ else
>
> (4) var2 = var ? 'this' : 'that';
> ^ else FALSE, then this
>
> (5) var2 = var ? 'this' : 'that';
> ^ assign results to var2
>
>
> As for the origins, I believe it comes from C, as do a number of
> constructs in both JavaScript and PHP. (PHP supports ternary form as
> well.) It's interesting to note that it isn't considered a complete
> statement in itself. The following isn't complete:
>
> ( var ) ? 'this' : 'that';
>
> If must be used as part of a complete statement such as this one:
>
> var2 = (var) ? 'this' : 'that';
>
> The returned value must be assigned to something or used in some manner.
> Is this more what you were looking for?
>
> Triche
>
>
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
--
Cutter
____________
http://blog.cutterscrossing.com
"The Past is a Memory
The Future a Dream
But Today is a Gift
That's why they call it
The Present"
More information about the Javascript
mailing list