具有多个条件的JS嵌套三进制

问题描述 投票:0回答:1

基本上,我有以下问题:

if condition A & B are true ->. do thing A
if only condition A is true -> do thing B 
else -> do thing C

我尝试过这个:

const myThing = conditionA ? conditionB ? thingA :
conditionA ? thingB : thingC;

它不喜欢语法,但是我不确定它有什么问题。

javascript reactjs conditional-operator
1个回答
1
投票
(() => { if (conditionA && conditionB) { return thingA; } else if (conditionA) { return thingB; } else { return thingC; } })()

0
投票
© www.soinside.com 2019 - 2024. All rights reserved.