Ternary operation in CoffeeScript

前端 未结 7 1449
生来不讨喜
生来不讨喜 2020-12-04 06:56

I need to set value to a that depends on a condition.

What is the shortest way to do this with CoffeeScript?

E.g. this is how I\'d do it in Java

7条回答
  •  有刺的猬
    2020-12-04 07:32

    Since everything is an expression, and thus results in a value, you can just use if/else.

    a = if true then 5 else 10
    a = if false then 5 else 10
    

    You can see more about expression examples here.

提交回复
热议问题