0

I am working on a BIRT Report and one of the fields contains the following expression:

dataSetRow["user_id"] != dataSetRow["creatorId"] ? dataSetRow["orderCreator"] : ''

What is the logic of this statement?

Hariprasad
  • 3,556
  • 2
  • 24
  • 40
Orin
  • 419
  • 1
  • 5
  • 10
  • 1
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator for reference on the ternary operator – scrappedcola Apr 20 '15 at 19:40
  • the expression is called ternary operator..short form of if else where the expression evaluate based on true or false – Lucky Apr 20 '15 at 19:43

1 Answers1

2

That statement is the equivalent of the code below, and is called the 'ternary' operator:

var value;

if(dataSetRow["creatorId"]){
    value = dataSetRow["orderCreator"];
}
else{
    value = '';
}

//To be clear, this isn't assigning to anything - this is the same expression you have in your question.
dataSetRow["user_id"] != value

You could use that expression, which returns a boolean, in an if block, for example:

if(dataSetRow["user_id"] != value){
    //Do something
}
p e p
  • 6,593
  • 2
  • 23
  • 32