January 16, 2003

Javascript Conditional Operator

The conditional operator in Javascript is the only ternary operator (three operands).

greeting = "hello" + ((username !=null) ? username : "there");

The first operand goes before the ?, the second goes between the ? and the :, and the third goes after the :.

The first operand of the conditional operator must have a boolean value — usually the result of a comparison expression. The second and third operands may have any value. If the first operand is true, then the value of the conditional expression is the value of the second operand. If it is false, then the value is the value of the third operand.

Post Info

Tagged As Javascript

Comments are Open (0)

Posted at 12:00 PM

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Search
Comments on this post
Categories
Info
Tony Stephens
Copyright © 1995-2005
Site Version:
10
Licensed:
Creative Commons
Validate:
XHTML, CSS, 508, RSS
Subscribe
Blog-Fu, Link-Fu