n8n LabIntermediate
Use JavaScript Ternary Operator in n8n Expressions
If the score is greater than 50, return 'Pass', otherwise return 'Fail'.
Live Execution Simulator
Idle
π₯
Incoming Data
βοΈ
n8n Node
π―
Next Step
> Ready. Type your expression below and click "Check Answer" to run the node.
Incoming Payload / Data:
{
"score": 85
}
$json.score > 50 ?
βοΈ Your expression is executed against test data β any correct solution passes. +20 XP
β Solution & explanation
$json.score > 50 ? 'Pass' : 'Fail'
Output: Pass
The ternary operator is a one-line if/else:
condition ? valueIfTrue : valueIfFalse. Since 85 > 50, the expression returns 'Pass'.π‘ Pro tip: Ternaries can be nested for three outcomes, but anything beyond that is easier to maintain in an IF or Switch node.
Also accepted: "Pass" : "Fail"
π Ternary operator ? : reference: syntax & more examples →