Page 1 of 1
: operator.
Posted: Sun Aug 06, 2006 4:59 pm
by JellyFish
What does the ":" operator do, if it is an operator? Give some examples, along with a good explanation, on how ":" works.
Thanks.
Posted: Sun Aug 06, 2006 5:10 pm
by feyd
It isn't an operator of it's own as far as I know. Off the top of my head, there are two uses for it in Javascript (I must assume you are referring to it since you posted in Client Side.) The first is with the ternary operator
expression ? true-expression : false-expression. The other is involved in JSON where it follows a property/method name
Code: Select all
var foo = {hi: 'cheese', spam: 'tasty'};
Posted: Sun Aug 06, 2006 5:33 pm
by JellyFish
Yes I meant JavaScript, thanks for that.

But if it's not an operator then what is it?
Posted: Sun Aug 06, 2006 5:38 pm
by feyd
For the ternary, it's part of the operator, but it isn't the or a operator.
For JSON, it's a separator, like => is for array notation in PHP.
Posted: Mon Aug 07, 2006 2:36 pm
by JellyFish
Wait a minute. What's the ternary operator? Is it "?"? I've seen this operator before and it was on my list of things to find out, so to speek. What does this operator to and how does it work?
Posted: Mon Aug 07, 2006 2:41 pm
by hawleyjr
Posted: Mon Aug 07, 2006 3:05 pm
by JellyFish
So "?:" is known as the "Conditional Operator"? From my research, it seems kinda like an if statement.
So if the condition in parenthesis is true then the following after "?" is executed. If false then the following after ":" is executed. In the example above, x equals 5.
Correct me if I'm wrong.

Posted: Mon Aug 07, 2006 3:07 pm
by Luke
that's right
Posted: Mon Aug 07, 2006 3:20 pm
by JellyFish
Then I guess this topic is closed.
Thank you all for your efforts.
