Tuesday, March 23, 2010

JavaScript IIF

A control statement (IIF) in JavaScript. A very simple terminology reference that might be used in a day to day programming paradigm.

Syntax

(CONDITION)?'OUTPUT_WHEN_SATISFIED':'OUTPUT_WHEN_NOT_SATISFIED';

Sample Snippet

    var sResult;
    sResult=(1==2)?'No':'Yes';
    alert(sResult);

Output: Yes will be displayed as a message.

Tags: JavaScript, JavaScriptIIF,JavaScript IIF, JavaScript iif, iif

4 comments:

  1. Where did you get the IIF from? It's already well known as Conditional Operator (?:) (AKA: Ternary Operator)
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator i.e:
    (boolean) ? (if-true-do-this) : (else-do-that) ;

    ReplyDelete
  2. @Roko, agreed that this is a ternary operator in JavaScript, had used the term for a better understanding and comparison with iif in ColdFusion

    ReplyDelete
  3. Thanks for sharing this quality information with us. I really enjoyed reading. Will surely going to share this URL with my friends.
    Webdesign

    ReplyDelete

Please leave your comments here...